1 ; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
3 ; Check position of bpf-preserve-static-offset pass in the pipeline:
4 ; preserve.static.offset call should be preserved long enough to allow
5 ; introduction of getelementptr.and.load after loops unrolling.
8 ; #define __ctx __attribute__((preserve_static_offset))
15 ; extern void consume(int);
17 ; void bar(struct foo *p){
18 ; unsigned long i = 0;
19 ; #pragma clang loop unroll(full)
25 ; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
26 ; | opt -passes=function(sroa) -S -o -
28 %struct.foo = type { i32, [4 x i32] }
30 ; Function Attrs: nounwind
31 define dso_local void @bar(ptr noundef %p) #0 {
35 while.cond: ; preds = %while.body, %entry
36 %i.0 = phi i64 [ 0, %entry ], [ %inc, %while.body ]
37 %cmp = icmp ult i64 %i.0, 2
38 br i1 %cmp, label %while.body, label %while.end
40 while.body: ; preds = %while.cond
41 %0 = call ptr @llvm.preserve.static.offset(ptr %p)
42 %b = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1
43 %inc = add i64 %i.0, 1
44 %arrayidx = getelementptr inbounds [4 x i32], ptr %b, i64 0, i64 %i.0
45 %1 = load i32, ptr %arrayidx, align 4, !tbaa !2
46 call void @consume(i32 noundef %1)
47 br label %while.cond, !llvm.loop !6
49 while.end: ; preds = %while.cond
53 ; CHECK: define dso_local void @bar(ptr nocapture noundef readonly %[[p:.*]])
54 ; CHECK: %[[v1:.*]] = tail call i32 (ptr, i1, i8, i8, i8, i1, ...)
55 ; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32
56 ; CHECK-SAME: (ptr readonly elementtype(i8) %[[p]],
57 ; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true, i64 immarg 4)
58 ; CHECK-SAME: #[[attrs:.*]], !tbaa
59 ; CHECK-NEXT: tail call void @consume(i32 noundef %[[v1]])
60 ; CHECK-NEXT: %[[v2:.*]] = tail call i32 (ptr, i1, i8, i8, i8, i1, ...)
61 ; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32
62 ; CHECK-SAME: (ptr readonly elementtype(i8) %[[p]],
63 ; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true, i64 immarg 8)
64 ; CHECK-SAME: #[[attrs]], !tbaa
65 ; CHECK-NEXT: tail call void @consume(i32 noundef %[[v2]])
66 ; CHECK: attributes #[[attrs]] = { memory(argmem: read) }
68 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
69 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
71 declare void @consume(i32 noundef) #2
73 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
74 declare ptr @llvm.preserve.static.offset(ptr readnone) #3
76 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
77 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
79 attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
80 attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
81 attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
82 attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
84 !llvm.module.flags = !{!0}
87 !0 = !{i32 1, !"wchar_size", i32 4}
90 !3 = !{!"int", !4, i64 0}
91 !4 = !{!"omnipotent char", !5, i64 0}
92 !5 = !{!"Simple C/C++ TBAA"}
93 !6 = distinct !{!6, !7, !8}
94 !7 = !{!"llvm.loop.mustprogress"}
95 !8 = !{!"llvm.loop.unroll.full"}