1; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s 2; 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. 6; 7; Source: 8; #define __ctx __attribute__((preserve_static_offset)) 9; 10; struct foo { 11; int a; 12; int b[4]; 13; } __ctx; 14; 15; extern void consume(int); 16; 17; void bar(struct foo *p){ 18; unsigned long i = 0; 19; #pragma clang loop unroll(full) 20; while (i < 2) 21; consume(p->b[i++]); 22; } 23; 24; Compilation flag: 25; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \ 26; | opt -passes=function(sroa) -S -o - 27 28%struct.foo = type { i32, [4 x i32] } 29 30; Function Attrs: nounwind 31define dso_local void @bar(ptr noundef %p) #0 { 32entry: 33 br label %while.cond 34 35while.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 39 40while.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 48 49while.end: ; preds = %while.cond 50 ret void 51} 52 53; CHECK: define dso_local void @bar(ptr noundef readonly captures(none) %[[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) } 67 68; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) 69declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1 70 71declare void @consume(i32 noundef) #2 72 73; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 74declare ptr @llvm.preserve.static.offset(ptr readnone) #3 75 76; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) 77declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1 78 79attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 80attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } 81attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 82attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 83 84!llvm.module.flags = !{!0} 85!llvm.ident = !{!1} 86 87!0 = !{i32 1, !"wchar_size", i32 4} 88!1 = !{!"clang"} 89!2 = !{!3, !3, i64 0} 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"} 96