1; RUN: opt -O2 %s | llvm-dis > %t1 2; RUN: llc -filetype=asm -o - %t1 | FileCheck %s 3; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck %s 4; RUN: opt -passes='default<O2>' %s | llvm-dis > %t1 5; RUN: llc -filetype=asm -o - %t1 | FileCheck %s 6; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck %s 7; Source code: 8; struct t { 9; int a; 10; } __attribute__((preserve_access_index)); 11; int foo(ptr); 12; int test(struct t *arg) { 13; long param[1]; 14; param[0] = (long)&arg->a; 15; return foo(param); 16; } 17; Compiler flag to generate IR: 18; clang -target bpf -S -O2 -g -emit-llvm -Xclang -disable-llvm-passes test.c 19 20target triple = "bpf" 21 22%struct.t = type { i32 } 23 24; Function Attrs: nounwind 25define dso_local i32 @test(ptr %arg) local_unnamed_addr #0 !dbg !14 { 26entry: 27 %param = alloca [1 x i64], align 8 28 call void @llvm.dbg.value(metadata ptr %arg, metadata !22, metadata !DIExpression()), !dbg !27 29 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %param) #5, !dbg !28 30 call void @llvm.dbg.declare(metadata ptr %param, metadata !23, metadata !DIExpression()), !dbg !29 31 %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.ts(ptr elementtype(%struct.t) %arg, i32 0, i32 0), !dbg !30, !llvm.preserve.access.index !18 32 %1 = ptrtoint ptr %0 to i64, !dbg !31 33 store i64 %1, ptr %param, align 8, !dbg !33, !tbaa !34 34 %call = call i32 @foo(ptr nonnull %param) #5, !dbg !38 35 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %param) #5, !dbg !39 36 ret i32 %call, !dbg !40 37} 38 39; CHECK: r[[OFFSET:[0-9]+]] = 0 40; CHECK: r1 += r[[OFFSET]] 41; CHECK: *(u64 *)(r10 - 8) = r1 42 43; Function Attrs: nounwind readnone speculatable 44declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 45 46; Function Attrs: argmemonly nounwind 47declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #2 48 49; Function Attrs: nounwind readnone 50declare ptr @llvm.preserve.struct.access.index.p0.p0.ts(ptr, i32, i32) #3 51 52declare !dbg !5 dso_local i32 @foo(ptr) local_unnamed_addr #4 53 54; Function Attrs: argmemonly nounwind 55declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #2 56 57; Function Attrs: nounwind readnone speculatable 58declare void @llvm.dbg.value(metadata, metadata, metadata) #1 59 60attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } 61attributes #1 = { nounwind readnone speculatable } 62attributes #2 = { argmemonly nounwind } 63attributes #3 = { nounwind readnone } 64attributes #4 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } 65attributes #5 = { nounwind } 66 67!llvm.dbg.cu = !{!0} 68!llvm.module.flags = !{!10, !11, !12} 69!llvm.ident = !{!13} 70 71!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 4f995959a05ae94cc4f9cc80035f7e4b3ecd2d88)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None) 72!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core") 73!2 = !{} 74!3 = !{!4, !5} 75!4 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed) 76!5 = !DISubprogram(name: "foo", scope: !1, file: !1, line: 4, type: !6, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2) 77!6 = !DISubroutineType(types: !7) 78!7 = !{!8, !9} 79!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 80!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) 81!10 = !{i32 7, !"Dwarf Version", i32 4} 82!11 = !{i32 2, !"Debug Info Version", i32 3} 83!12 = !{i32 1, !"wchar_size", i32 4} 84!13 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 4f995959a05ae94cc4f9cc80035f7e4b3ecd2d88)"} 85!14 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 5, type: !15, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !21) 86!15 = !DISubroutineType(types: !16) 87!16 = !{!8, !17} 88!17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64) 89!18 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t", file: !1, line: 1, size: 32, elements: !19) 90!19 = !{!20} 91!20 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !18, file: !1, line: 2, baseType: !8, size: 32) 92!21 = !{!22, !23} 93!22 = !DILocalVariable(name: "arg", arg: 1, scope: !14, file: !1, line: 5, type: !17) 94!23 = !DILocalVariable(name: "param", scope: !14, file: !1, line: 6, type: !24) 95!24 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 64, elements: !25) 96!25 = !{!26} 97!26 = !DISubrange(count: 1) 98!27 = !DILocation(line: 0, scope: !14) 99!28 = !DILocation(line: 6, column: 5, scope: !14) 100!29 = !DILocation(line: 6, column: 10, scope: !14) 101!30 = !DILocation(line: 7, column: 28, scope: !14) 102!31 = !DILocation(line: 7, column: 16, scope: !14) 103!32 = !DILocation(line: 7, column: 5, scope: !14) 104!33 = !DILocation(line: 7, column: 14, scope: !14) 105!34 = !{!35, !35, i64 0} 106!35 = !{!"long", !36, i64 0} 107!36 = !{!"omnipotent char", !37, i64 0} 108!37 = !{!"Simple C/C++ TBAA"} 109!38 = !DILocation(line: 8, column: 12, scope: !14) 110!39 = !DILocation(line: 9, column: 1, scope: !14) 111!40 = !DILocation(line: 8, column: 5, scope: !14) 112