65 lines · plain
1; RUN: opt -O2 -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 bar {9; int aa;10; int bb;11; };12; 13; struct foo {14; int a;15; struct bar b;16; } __ctx;17; 18; void buz(struct foo *p) {19; p->b.bb = 42;20; }21;22; Compilation flag:23; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \24; | opt -passes=function(sroa) -S -o -25 26%struct.foo = type { i32, %struct.bar }27%struct.bar = type { i32, i32 }28 29; Function Attrs: nounwind30define dso_local void @buz(ptr noundef %p) #0 {31entry:32 %0 = call ptr @llvm.preserve.static.offset(ptr %p)33 %b = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 134 %bb = getelementptr inbounds %struct.bar, ptr %b, i32 0, i32 135 store i32 42, ptr %bb, align 4, !tbaa !236 ret void37}38 39; CHECK: define dso_local void @buz(ptr noundef writeonly captures(none) %[[p:.*]])40; CHECK: tail call void (i32, ptr, i1, i8, i8, i8, i1, ...)41; CHECK-SAME: @llvm.bpf.getelementptr.and.store.i3242; CHECK-SAME: (i32 42,43; CHECK-SAME: ptr writeonly elementtype(%struct.foo) %[[p]],44; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1, i32 immarg 1)45; CHECK-SAME: #[[v2:.*]], !tbaa46; CHECK: attributes #[[v2]] = { memory(argmem: write) }47 48; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)49declare ptr @llvm.preserve.static.offset(ptr readnone) #150 51attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }52attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }53 54!llvm.module.flags = !{!0}55!llvm.ident = !{!1}56 57!0 = !{i32 1, !"wchar_size", i32 4}58!1 = !{!"clang"}59!2 = !{!3, !4, i64 8}60!3 = !{!"foo", !4, i64 0, !7, i64 4}61!4 = !{!"int", !5, i64 0}62!5 = !{!"omnipotent char", !6, i64 0}63!6 = !{!"Simple C/C++ TBAA"}64!7 = !{!"bar", !4, i64 0, !4, i64 4}65