74 lines · plain
1; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s2;3; Check that bpf-preserve-static-offset keeps track of 'inbounds' flags while4; folding chain of GEP instructions.5;6; Source (IR modified by hand):7; #define __ctx __attribute__((preserve_static_offset))8; 9; struct foo {10; int a[2];11; };12; 13; struct bar {14; int a;15; struct foo b;16; } __ctx;17; 18; extern void consume(int);19; 20; void buz(struct bar *p) {21; consume(p->b.a[1]);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; Modified to remove one of the 'inbounds' from one of the GEP instructions.29 30%struct.bar = type { i32, %struct.foo }31%struct.foo = type { [2 x i32] }32 33; Function Attrs: nounwind34define dso_local void @buz(ptr noundef %p) #0 {35entry:36 %0 = call ptr @llvm.preserve.static.offset(ptr %p)37 %b = getelementptr inbounds %struct.bar, ptr %0, i32 0, i32 138 %a = getelementptr %struct.foo, ptr %b, i32 0, i32 039 %arrayidx = getelementptr inbounds [2 x i32], ptr %a, i64 0, i64 140 %1 = load i32, ptr %arrayidx, align 4, !tbaa !241 call void @consume(i32 noundef %1)42 ret void43}44 45; CHECK: %[[v1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...)46; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i3247; CHECK-SAME: (ptr readonly elementtype(%struct.bar) %{{[^,]+}},48; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 false,49; ^^^^^^^^50; not inbounds51; CHECK-SAME: i32 immarg 0, i32 immarg 1, i32 immarg 0, i64 immarg 1)52; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^53; folded gep chain54; CHECK-NEXT: call void @consume(i32 noundef %[[v1]])55 56declare void @consume(i32 noundef) #157 58; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)59declare ptr @llvm.preserve.static.offset(ptr readnone) #260 61attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }62attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }63attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }64 65!llvm.module.flags = !{!0}66!llvm.ident = !{!1}67 68!0 = !{i32 1, !"wchar_size", i32 4}69!1 = !{!"clang"}70!2 = !{!3, !3, i64 0}71!3 = !{!"int", !4, i64 0}72!4 = !{!"omnipotent char", !5, i64 0}73!5 = !{!"Simple C/C++ TBAA"}74