1 ; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
3 ; Check handling of a simple load instruction by bpf-preserve-static-offset.
5 ; - presence of gep.and.load intrinsic call
6 ; - correct attributes for intrinsic call
7 ; - presence of tbaa annotations
10 ; #define __ctx __attribute__((preserve_static_offset))
17 ; extern void consume(int);
19 ; void bar(struct foo *p) {
24 ; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
25 ; | opt -passes=function(sroa) -S -o -
27 %struct.foo = type { i32, i32 }
29 ; Function Attrs: nounwind
30 define dso_local void @bar(ptr noundef %p) #0 {
32 %0 = call ptr @llvm.preserve.static.offset(ptr %p)
33 %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1
34 %1 = load i32, ptr %a, align 4, !tbaa !2
35 call void @consume(i32 noundef %1)
39 ; CHECK: define dso_local void @bar(ptr noundef %[[p:.*]])
40 ; CHECK: %[[a1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...)
41 ; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32
42 ; CHECK-SAME: (ptr readonly elementtype(%struct.foo) %[[p]],
43 ; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1)
44 ; CHECK-SAME: #[[v1:.*]], !tbaa
45 ; CHECK-NEXT: call void @consume(i32 noundef %[[a1]])
48 ; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32(ptr nocapture, {{.*}}) #[[v2:.*]]
50 ; CHECK: attributes #[[v2]] = { nocallback nofree nounwind willreturn }
51 ; CHECK: attributes #[[v1]] = { memory(argmem: read) }
53 declare void @consume(i32 noundef) #1
55 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
56 declare ptr @llvm.preserve.static.offset(ptr readnone) #2
58 attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
59 attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
60 attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
62 !llvm.module.flags = !{!0}
65 !0 = !{i32 1, !"wchar_size", i32 4}
68 !3 = !{!"foo", !4, i64 0, !4, i64 4}
69 !4 = !{!"int", !5, i64 0}
70 !5 = !{!"omnipotent char", !6, i64 0}
71 !6 = !{!"Simple C/C++ TBAA"}