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