1 ; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
3 ; Check handling of atomic load instruction by bpf-preserve-static-offset.
6 ; #define __ctx __attribute__((preserve_static_offset))
13 ; extern void consume(int);
15 ; void bar(struct foo *p) {
17 ; __atomic_load(&p->a, &r, 2);
22 ; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
23 ; | opt -passes=function(sroa) -S -o -
25 %struct.foo = type { i32, i32 }
27 ; Function Attrs: nounwind
28 define dso_local void @bar(ptr noundef %p) #0 {
30 %0 = call ptr @llvm.preserve.static.offset(ptr %p)
31 %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1
32 %1 = load atomic i32, ptr %a acquire, align 4
33 call void @consume(i32 noundef %1)
37 ; CHECK: %[[a1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...)
38 ; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32
39 ; CHECK-SAME: (ptr elementtype(%struct.foo) %[[p:.*]],
40 ; i1 false, i8 4, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1)
43 ; CHECK-NOT: #{{[0-9]+}}
44 ; CHECK-NEXT: call void @consume(i32 noundef %[[a1]])
46 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
47 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
49 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
50 declare ptr @llvm.preserve.static.offset(ptr readnone) #2
52 declare void @consume(i32 noundef) #3
54 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
55 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
57 attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
58 attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
59 attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
60 attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
62 !llvm.module.flags = !{!0}
65 !0 = !{i32 1, !"wchar_size", i32 4}