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