xref: /llvm-project/llvm/test/CodeGen/BPF/preserve-static-offset/load-volatile.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 a volatile load instruction by bpf-preserve-static-offset.
4;
5; Source:
6;    #define __ctx __attribute__((preserve_static_offset))
7;
8;    struct foo {
9;      int _;
10;      volatile int a;
11;    } __ctx;
12;
13;    extern void consume(int);
14;
15;    void bar(struct foo *p) {
16;      consume(p->a);
17;    }
18;
19; Compilation flag:
20;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
21;       | opt -passes=function(sroa) -S -o -
22
23%struct.foo = type { i32, i32 }
24
25; Function Attrs: nounwind
26define dso_local void @bar(ptr noundef %p) #0 {
27entry:
28  %0 = call ptr @llvm.preserve.static.offset(ptr %p)
29  %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1
30  %1 = load volatile i32, ptr %a, align 4, !tbaa !2
31  call void @consume(i32 noundef %1)
32  ret void
33}
34
35; CHECK:      %[[a1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...)
36; CHECK-SAME:    @llvm.bpf.getelementptr.and.load.i32
37; CHECK-SAME:      (ptr elementtype(%struct.foo) %{{[^,]+}},
38; CHECK-SAME:       i1 true, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1)
39;                   ^^^^^^^^
40;                   volatile
41; CHECK-NOT:  #{{[0-9]+}}
42; CHECK-NEXT: call void @consume(i32 noundef %[[a1]])
43
44declare void @consume(i32 noundef) #1
45
46; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
47declare ptr @llvm.preserve.static.offset(ptr readnone) #2
48
49attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
50attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
51attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
52
53!llvm.module.flags = !{!0}
54!llvm.ident = !{!1}
55
56!0 = !{i32 1, !"wchar_size", i32 4}
57!1 = !{!"clang"}
58!2 = !{!3, !4, i64 4}
59!3 = !{!"foo", !4, i64 0, !4, i64 4}
60!4 = !{!"int", !5, i64 0}
61!5 = !{!"omnipotent char", !6, i64 0}
62!6 = !{!"Simple C/C++ TBAA"}
63