106 lines · plain
1; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s2;3; Source:4; #define __ctx __attribute__((preserve_static_offset))5; #define __pai __attribute__((preserve_access_index))6; 7; struct foo {8; int a;9; int b;10; };11; 12; struct bar {13; int _1;14; int _2;15; struct foo c;16; } __pai __ctx;17; 18; int buz(struct bar *p) {19; return p->c.b;20; }21; 22; Compilation flag:23; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes \24; -debug-info-kind=limited -o - \25; | opt -passes=function(sroa) -S -o -26 27%struct.bar = type { i32, i32, %struct.foo }28%struct.foo = type { i32, i32 }29 30; Function Attrs: nounwind31define dso_local i32 @buz(ptr noundef %p) #0 !dbg !5 {32entry:33 call void @llvm.dbg.value(metadata ptr %p, metadata !20, metadata !DIExpression()), !dbg !2134 %0 = call ptr @llvm.preserve.static.offset(ptr %p), !dbg !2235 %1 = call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.bar) %0, i32 2, i32 2), !dbg !22, !llvm.preserve.access.index !1036 %b = getelementptr inbounds %struct.foo, ptr %1, i32 0, i32 1, !dbg !2337 %2 = load i32, ptr %b, align 4, !dbg !23, !tbaa !2438 ret i32 %2, !dbg !3039}40 41; CHECK: define dso_local i32 @buz(ptr noundef %[[p:.*]]) {{.*}} {42; CHECK-NEXT: entry:43; CHECK-NEXT: #dbg_value44; CHECK-NEXT: %[[b1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...)45; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i3246; CHECK-SAME: (ptr readonly elementtype(%struct.bar) %[[p]],47; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 2, i32 immarg 1)48; CHECK-SAME: #[[v5:.*]], !tbaa49; CHECK-NEXT: ret i32 %[[b1]]50; CHECK-NEXT: }51 52; CHECK: attributes #[[v5]] = { memory(argmem: read) }53 54 55; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)56declare void @llvm.dbg.declare(metadata, metadata, metadata) #157 58; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)59declare ptr @llvm.preserve.static.offset(ptr readnone) #160 61; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)62declare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32 immarg, i32 immarg) #263 64; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)65declare void @llvm.dbg.value(metadata, metadata, metadata) #166 67attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }68attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }69attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }70 71!llvm.dbg.cu = !{!0}72!llvm.module.flags = !{!2, !3}73!llvm.ident = !{!4}74 75!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)76!1 = !DIFile(filename: "some-file.c", directory: "/some/dir/")77!2 = !{i32 2, !"Debug Info Version", i32 3}78!3 = !{i32 1, !"wchar_size", i32 4}79!4 = !{!"clang"}80!5 = distinct !DISubprogram(name: "buz", scope: !1, file: !1, line: 15, type: !6, scopeLine: 15, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !19)81!6 = !DISubroutineType(types: !7)82!7 = !{!8, !9}83!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)84!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64)85!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !1, line: 9, size: 128, elements: !11)86!11 = !{!12, !13, !14}87!12 = !DIDerivedType(tag: DW_TAG_member, name: "_1", scope: !10, file: !1, line: 10, baseType: !8, size: 32)88!13 = !DIDerivedType(tag: DW_TAG_member, name: "_2", scope: !10, file: !1, line: 11, baseType: !8, size: 32, offset: 32)89!14 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !10, file: !1, line: 12, baseType: !15, size: 64, offset: 64)90!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !1, line: 4, size: 64, elements: !16)91!16 = !{!17, !18}92!17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 5, baseType: !8, size: 32)93!18 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !15, file: !1, line: 6, baseType: !8, size: 32, offset: 32)94!19 = !{!20}95!20 = !DILocalVariable(name: "p", arg: 1, scope: !5, file: !1, line: 15, type: !9)96!21 = !DILocation(line: 0, scope: !5)97!22 = !DILocation(line: 16, column: 13, scope: !5)98!23 = !DILocation(line: 16, column: 15, scope: !5)99!24 = !{!25, !26, i64 12}100!25 = !{!"bar", !26, i64 0, !26, i64 4, !29, i64 8}101!26 = !{!"int", !27, i64 0}102!27 = !{!"omnipotent char", !28, i64 0}103!28 = !{!"Simple C/C++ TBAA"}104!29 = !{!"foo", !26, i64 0, !26, i64 4}105!30 = !DILocation(line: 16, column: 3, scope: !5)106