78 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 GEP chains that end by4; getelementptr.and.store.5;6; Source (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; And modified to fold last getelementptr/store as a single28; getelementptr.and.store.29 30%struct.foo = type { i32, %struct.bar }31%struct.bar = type { i32, 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.foo, ptr %0, i32 0, i32 138 call void (i32, ptr, i1, i8, i8, i8, i1, ...)39 @llvm.bpf.getelementptr.and.store.i3240 (i32 42,41 ptr writeonly elementtype(%struct.bar) %b,42 i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1)43 #3, !tbaa !244 ret void45}46 47; CHECK: define dso_local void @buz(ptr noundef %[[p:.*]])48; CHECK: call void (i32, ptr, i1, i8, i8, i8, i1, ...)49; CHECK-SAME: @llvm.bpf.getelementptr.and.store.i3250; CHECK-SAME: (i32 42,51; CHECK-SAME: ptr writeonly elementtype(%struct.foo) %[[p]],52; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1, i32 immarg 1)53; CHECK-SAME: #[[v2:.*]], !tbaa54; CHECK: attributes #[[v2]] = { memory(argmem: write) }55 56; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)57declare ptr @llvm.preserve.static.offset(ptr readnone) #158 59; Function Attrs: nocallback nofree nounwind willreturn60declare void @llvm.bpf.getelementptr.and.store.i32(i32, ptr nocapture, i1 immarg, i8 immarg, i8 immarg, i8 immarg, i1 immarg, ...) #261 62attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }63attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }64attributes #2 = { nocallback nofree nounwind willreturn }65attributes #3 = { memory(argmem: write) }66 67!llvm.module.flags = !{!0}68!llvm.ident = !{!1}69 70!0 = !{i32 1, !"wchar_size", i32 4}71!1 = !{!"clang"}72!2 = !{!3, !4, i64 8}73!3 = !{!"foo", !4, i64 0, !7, i64 4}74!4 = !{!"int", !5, i64 0}75!5 = !{!"omnipotent char", !6, i64 0}76!6 = !{!"Simple C/C++ TBAA"}77!7 = !{!"bar", !4, i64 0, !4, i64 4}78