1; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s 2; 3; Check that bpf-preserve-static-offset keeps track of 'inbounds' flags while 4; folding chain of GEP instructions. 5; 6; Source (IR modified by hand): 7; #define __ctx __attribute__((preserve_static_offset)) 8; 9; struct bar { 10; int aa; 11; int bb; 12; }; 13; 14; struct foo { 15; int a; 16; struct bar b; 17; } __ctx; 18; 19; void buz(struct foo *p) { 20; p->b.bb = 42; 21; } 22; 23; Compilation flag: 24; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \ 25; | opt -passes=function(sroa) -S -o - 26; 27; Modified to remove one of the 'inbounds' from one of the GEP instructions. 28 29%struct.foo = type { i32, %struct.bar } 30%struct.bar = type { i32, i32 } 31 32; Function Attrs: nounwind 33define dso_local void @buz(ptr noundef %p) #0 { 34entry: 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 39 ret void 40} 41 42; CHECK: define dso_local void @buz(ptr noundef writeonly captures(none) %[[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) } 50 51; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 52declare ptr @llvm.preserve.static.offset(ptr readnone) #1 53 54attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 55attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 56 57!llvm.module.flags = !{!0} 58!llvm.ident = !{!1} 59 60!0 = !{i32 1, !"wchar_size", i32 4} 61!1 = !{!"clang"} 62!2 = !{!3, !4, i64 8} 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} 68