72 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; The GEP chain in this example has unexpected shape and thus is5; folded as i8 access.6;7; Source:8; #define __ctx __attribute__((preserve_static_offset))9; 10; struct foo {11; char a[2];12; };13; 14; struct bar {15; char a;16; struct foo b;17; } __ctx;18; 19; extern void consume(char);20; 21; void buz(struct bar *p) {22; consume((&p->b)[1].a[1]);23; }24;25; Compilation flag:26; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \27; | opt -passes=function(sroa) -S -o -28 29%struct.bar = type { i8, %struct.foo }30%struct.foo = type { [2 x i8] }31 32; Function Attrs: nounwind33define dso_local void @buz(ptr noundef %p) #0 {34entry:35 %0 = call ptr @llvm.preserve.static.offset(ptr %p)36 %b = getelementptr inbounds %struct.bar, ptr %0, i32 0, i32 137 %arrayidx = getelementptr inbounds %struct.foo, ptr %b, i64 138; ^^^^^39; folded as i8 access because of this index40 %a = getelementptr inbounds %struct.foo, ptr %arrayidx, i32 0, i32 041 %arrayidx1 = getelementptr inbounds [2 x i8], ptr %a, i64 0, i64 142 %1 = load i8, ptr %arrayidx1, align 1, !tbaa !243 call void @consume(i8 noundef signext %1)44 ret void45}46 47; CHECK: %[[v1:.*]] = call i8 (ptr, i1, i8, i8, i8, i1, ...)48; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i849; CHECK-SAME: (ptr readonly elementtype(i8) %{{[^,]+}},50; CHECK-SAME: i1 false, i8 0, i8 1, i8 0, i1 true, i64 immarg 4)51; ^^^^^^^^^^^^52; offset from 'struct bar' start53; CHECK-NEXT: call void @consume(i8 noundef signext %[[v1]])54 55declare void @consume(i8 noundef signext) #156 57; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)58declare ptr @llvm.preserve.static.offset(ptr readnone) #259 60attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }61attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }62attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }63 64!llvm.module.flags = !{!0}65!llvm.ident = !{!1}66 67!0 = !{i32 1, !"wchar_size", i32 4}68!1 = !{!"clang"}69!2 = !{!3, !3, i64 0}70!3 = !{!"omnipotent char", !4, i64 0}71!4 = !{!"Simple C/C++ TBAA"}72