69 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 folds chain of GEP instructions.4;5; Source:6; #define __ctx __attribute__((preserve_static_offset))7; 8; struct foo {9; int a[2];10; };11; 12; struct bar {13; int a;14; struct foo b;15; } __ctx;16; 17; extern void consume(int);18; 19; void buz(struct bar *p) {20; consume(p->b.a[1]);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%struct.bar = type { i32, %struct.foo }28%struct.foo = type { [2 x i32] }29 30; Function Attrs: nounwind31define dso_local void @buz(ptr noundef %p) #0 {32entry:33 %0 = call ptr @llvm.preserve.static.offset(ptr %p)34 %b = getelementptr inbounds %struct.bar, ptr %0, i32 0, i32 135 %a = getelementptr inbounds %struct.foo, ptr %b, i32 0, i32 036 %arrayidx = getelementptr inbounds [2 x i32], ptr %a, i64 0, i64 137 %1 = load i32, ptr %arrayidx, align 4, !tbaa !238 call void @consume(i32 noundef %1)39 ret void40}41 42; CHECK: %[[v1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...)43; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i3244; CHECK-SAME: (ptr readonly elementtype(%struct.bar) %{{[^,]+}},45; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true,46; CHECK-SAME: i32 immarg 0, i32 immarg 1, i32 immarg 0, i64 immarg 1)47; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^48; folded gep chain49; CHECK-NEXT: call void @consume(i32 noundef %[[v1]])50 51declare void @consume(i32 noundef) #152 53; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)54declare ptr @llvm.preserve.static.offset(ptr readnone) #255 56attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }57attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }58attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }59 60!llvm.module.flags = !{!0}61!llvm.ident = !{!1}62 63!0 = !{i32 1, !"wchar_size", i32 4}64!1 = !{!"clang"}65!2 = !{!3, !3, i64 0}66!3 = !{!"int", !4, i64 0}67!4 = !{!"omnipotent char", !5, i64 0}68!5 = !{!"Simple C/C++ TBAA"}69