xref: /llvm-project/llvm/test/CodeGen/BPF/preserve-static-offset/load-atomic.ll (revision 030b8cb1561db4161b108b59044717d89026cf70)
1*030b8cb1SEduard Zingerman; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
2*030b8cb1SEduard Zingerman;
3*030b8cb1SEduard Zingerman; Check handling of atomic load instruction by bpf-preserve-static-offset.
4*030b8cb1SEduard Zingerman;
5*030b8cb1SEduard Zingerman; Source:
6*030b8cb1SEduard Zingerman;    #define __ctx __attribute__((preserve_static_offset))
7*030b8cb1SEduard Zingerman;
8*030b8cb1SEduard Zingerman;    struct foo {
9*030b8cb1SEduard Zingerman;      int _;
10*030b8cb1SEduard Zingerman;      int a;
11*030b8cb1SEduard Zingerman;    } __ctx;
12*030b8cb1SEduard Zingerman;
13*030b8cb1SEduard Zingerman;    extern void consume(int);
14*030b8cb1SEduard Zingerman;
15*030b8cb1SEduard Zingerman;    void bar(struct foo *p) {
16*030b8cb1SEduard Zingerman;      int r;
17*030b8cb1SEduard Zingerman;      __atomic_load(&p->a, &r, 2);
18*030b8cb1SEduard Zingerman;      consume(r);
19*030b8cb1SEduard Zingerman;    }
20*030b8cb1SEduard Zingerman;
21*030b8cb1SEduard Zingerman; Compilation flag:
22*030b8cb1SEduard Zingerman;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
23*030b8cb1SEduard Zingerman;       | opt -passes=function(sroa) -S -o -
24*030b8cb1SEduard Zingerman
25*030b8cb1SEduard Zingerman%struct.foo = type { i32, i32 }
26*030b8cb1SEduard Zingerman
27*030b8cb1SEduard Zingerman; Function Attrs: nounwind
28*030b8cb1SEduard Zingermandefine dso_local void @bar(ptr noundef %p) #0 {
29*030b8cb1SEduard Zingermanentry:
30*030b8cb1SEduard Zingerman  %0 = call ptr @llvm.preserve.static.offset(ptr %p)
31*030b8cb1SEduard Zingerman  %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1
32*030b8cb1SEduard Zingerman  %1 = load atomic i32, ptr %a acquire, align 4
33*030b8cb1SEduard Zingerman  call void @consume(i32 noundef %1)
34*030b8cb1SEduard Zingerman  ret void
35*030b8cb1SEduard Zingerman}
36*030b8cb1SEduard Zingerman
37*030b8cb1SEduard Zingerman; CHECK:      %[[a1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...)
38*030b8cb1SEduard Zingerman; CHECK-SAME:    @llvm.bpf.getelementptr.and.load.i32
39*030b8cb1SEduard Zingerman; CHECK-SAME:      (ptr elementtype(%struct.foo) %[[p:.*]],
40*030b8cb1SEduard Zingerman;                   i1 false, i8 4, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1)
41*030b8cb1SEduard Zingerman;                             ^^^^
42*030b8cb1SEduard Zingerman;                          atomic order
43*030b8cb1SEduard Zingerman; CHECK-NOT:  #{{[0-9]+}}
44*030b8cb1SEduard Zingerman; CHECK-NEXT: call void @consume(i32 noundef %[[a1]])
45*030b8cb1SEduard Zingerman
46*030b8cb1SEduard Zingerman; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
47*030b8cb1SEduard Zingermandeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
48*030b8cb1SEduard Zingerman
49*030b8cb1SEduard Zingerman; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
50*030b8cb1SEduard Zingermandeclare ptr @llvm.preserve.static.offset(ptr readnone) #2
51*030b8cb1SEduard Zingerman
52*030b8cb1SEduard Zingermandeclare void @consume(i32 noundef) #3
53*030b8cb1SEduard Zingerman
54*030b8cb1SEduard Zingerman; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
55*030b8cb1SEduard Zingermandeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
56*030b8cb1SEduard Zingerman
57*030b8cb1SEduard Zingermanattributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
58*030b8cb1SEduard Zingermanattributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
59*030b8cb1SEduard Zingermanattributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
60*030b8cb1SEduard Zingermanattributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
61*030b8cb1SEduard Zingerman
62*030b8cb1SEduard Zingerman!llvm.module.flags = !{!0}
63*030b8cb1SEduard Zingerman!llvm.ident = !{!1}
64*030b8cb1SEduard Zingerman
65*030b8cb1SEduard Zingerman!0 = !{i32 1, !"wchar_size", i32 4}
66*030b8cb1SEduard Zingerman!1 = !{!"clang"}
67