1; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s 2; 3; Source: 4; #define __ctx __attribute__((preserve_static_offset)) 5; #define __pai __attribute__((preserve_access_index)) 6; 7; struct bar { 8; int a; 9; int b; 10; } __pai; 11; 12; struct buz { 13; int _1; 14; struct bar *b; 15; } __pai __ctx; 16; 17; void foo(struct buz *p) { 18; p->b->b = 42; 19; } 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.buz = type { i32, ptr } 28%struct.bar = type { i32, i32 } 29 30; Function Attrs: nounwind 31define dso_local void @foo(ptr noundef %p) #0 !dbg !5 { 32entry: 33 call void @llvm.dbg.value(metadata ptr %p, metadata !20, metadata !DIExpression()), !dbg !21 34 %0 = call ptr @llvm.preserve.static.offset(ptr %p), !dbg !22 35 %1 = call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.buz) %0, i32 1, i32 1), !dbg !22, !llvm.preserve.access.index !9 36 %2 = load ptr, ptr %1, align 8, !dbg !22, !tbaa !23 37 %3 = call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.bar) %2, i32 1, i32 1), !dbg !29, !llvm.preserve.access.index !15 38 store i32 42, ptr %3, align 4, !dbg !30, !tbaa !31 39 ret void, !dbg !33 40} 41 42; CHECK: define dso_local void @foo(ptr noundef %[[p:.*]]) {{.*}} { 43; CHECK-NEXT: entry: 44; CHECK-NEXT: #dbg_value 45; CHECK-NEXT: %[[v5:.*]] = call ptr (ptr, i1, i8, i8, i8, i1, ...) 46; CHECK-SAME: @llvm.bpf.getelementptr.and.load.p0 47; CHECK-SAME: (ptr readonly elementtype(%struct.buz) %[[p]], 48; CHECK-SAME: i1 false, i8 0, i8 1, i8 3, i1 true, i32 immarg 0, i32 immarg 1) 49; CHECK-SAME: #[[v6:.*]], !tbaa 50; CHECK-NEXT: %[[v8:.*]] = 51; CHECK-SAME: call ptr @llvm.preserve.struct.access.index.p0.p0 52; CHECK-SAME: (ptr elementtype(%struct.bar) %[[v5]], i32 1, i32 1), 53; CHECK-SAME: !dbg ![[#]], !llvm.preserve.access.index ![[#]] 54; CHECK-NEXT: store i32 42, ptr %[[v8]], align 4, !dbg ![[#]], !tbaa 55; CHECK-NEXT: ret void, !dbg 56; CHECK-NEXT: } 57 58; CHECK : attributes #[[v6]] = { memory(argmem: read) } 59 60 61; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 62declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 63 64; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 65declare ptr @llvm.preserve.static.offset(ptr readnone) #1 66 67; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none) 68declare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32 immarg, i32 immarg) #2 69 70; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 71declare void @llvm.dbg.value(metadata, metadata, metadata) #1 72 73attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 74attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 75attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) } 76 77!llvm.dbg.cu = !{!0} 78!llvm.module.flags = !{!2, !3} 79!llvm.ident = !{!4} 80 81!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) 82!1 = !DIFile(filename: "some-file.c", directory: "/some/dir/") 83!2 = !{i32 2, !"Debug Info Version", i32 3} 84!3 = !{i32 1, !"wchar_size", i32 4} 85!4 = !{!"clang"} 86!5 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 14, type: !6, scopeLine: 14, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !19) 87!6 = !DISubroutineType(types: !7) 88!7 = !{null, !8} 89!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64) 90!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "buz", file: !1, line: 9, size: 128, elements: !10) 91!10 = !{!11, !13} 92!11 = !DIDerivedType(tag: DW_TAG_member, name: "_1", scope: !9, file: !1, line: 10, baseType: !12, size: 32) 93!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 94!13 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !9, file: !1, line: 11, baseType: !14, size: 64, offset: 64) 95!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64) 96!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !1, line: 4, size: 64, elements: !16) 97!16 = !{!17, !18} 98!17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 5, baseType: !12, size: 32) 99!18 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !15, file: !1, line: 6, baseType: !12, size: 32, offset: 32) 100!19 = !{!20} 101!20 = !DILocalVariable(name: "p", arg: 1, scope: !5, file: !1, line: 14, type: !8) 102!21 = !DILocation(line: 0, scope: !5) 103!22 = !DILocation(line: 15, column: 6, scope: !5) 104!23 = !{!24, !28, i64 8} 105!24 = !{!"buz", !25, i64 0, !28, i64 8} 106!25 = !{!"int", !26, i64 0} 107!26 = !{!"omnipotent char", !27, i64 0} 108!27 = !{!"Simple C/C++ TBAA"} 109!28 = !{!"any pointer", !26, i64 0} 110!29 = !DILocation(line: 15, column: 9, scope: !5) 111!30 = !DILocation(line: 15, column: 11, scope: !5) 112!31 = !{!32, !25, i64 4} 113!32 = !{!"bar", !25, i64 0, !25, i64 4} 114!33 = !DILocation(line: 16, column: 1, scope: !5) 115