1 ; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
3 ; Check that bpf-preserve-static-offset keeps track of 'inbounds' flags while
4 ; folding chain of GEP instructions.
6 ; Source (IR modified by hand):
7 ; #define __ctx __attribute__((preserve_static_offset))
19 ; void buz(struct foo *p) {
24 ; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
25 ; | opt -passes=function(sroa) -S -o -
27 ; Modified to remove one of the 'inbounds' from one of the GEP instructions.
29 %struct.foo = type { i32, %struct.bar }
30 %struct.bar = type { i32, i32 }
32 ; Function Attrs: nounwind
33 define dso_local void @buz(ptr noundef %p) #0 {
35 %0 = call ptr @llvm.preserve.static.offset(ptr %p)
36 %b = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1
37 %bb = getelementptr %struct.bar, ptr %b, i32 0, i32 1
38 store i32 42, ptr %bb, align 4, !tbaa !2
42 ; CHECK: define dso_local void @buz(ptr nocapture noundef writeonly %[[p:.*]])
43 ; CHECK: tail call void (i32, ptr, i1, i8, i8, i8, i1, ...)
44 ; CHECK-SAME: @llvm.bpf.getelementptr.and.store.i32
45 ; CHECK-SAME: (i32 42,
46 ; CHECK-SAME: ptr writeonly elementtype(%struct.foo) %[[p]],
47 ; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 false, i32 immarg 0, i32 immarg 1, i32 immarg 1)
48 ; CHECK-SAME: #[[v2:.*]], !tbaa
49 ; CHECK: attributes #[[v2]] = { memory(argmem: write) }
51 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
52 declare ptr @llvm.preserve.static.offset(ptr readnone) #1
54 attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
55 attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
57 !llvm.module.flags = !{!0}
60 !0 = !{i32 1, !"wchar_size", i32 4}
63 !3 = !{!"foo", !4, i64 0, !7, i64 4}
64 !4 = !{!"int", !5, i64 0}
65 !5 = !{!"omnipotent char", !6, i64 0}
66 !6 = !{!"Simple C/C++ TBAA"}
67 !7 = !{!"bar", !4, i64 0, !4, i64 4}