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
10 ; } __attribute__((preserve_access_index));
12 ; int test(struct t *arg) {
14 ; param[0] = (long)&arg->a;
17 ; Compiler flag to generate IR:
18 ; clang -target bpf -S -O2 -g -emit-llvm -Xclang -disable-llvm-passes test.c
22 %struct.t = type { i32 }
24 ; Function Attrs: nounwind
25 define dso_local i32 @test(ptr %arg) local_unnamed_addr #0 !dbg !14 {
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
39 ; CHECK: r[[OFFSET:[0-9]+]] = 0
40 ; CHECK: r1 += r[[OFFSET]]
41 ; CHECK: *(u64 *)(r10 - 8) = r1
43 ; Function Attrs: nounwind readnone speculatable
44 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
46 ; Function Attrs: argmemonly nounwind
47 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #2
49 ; Function Attrs: nounwind readnone
50 declare ptr @llvm.preserve.struct.access.index.p0.p0.ts(ptr, i32, i32) #3
52 declare !dbg !5 dso_local i32 @foo(ptr) local_unnamed_addr #4
54 ; Function Attrs: argmemonly nounwind
55 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #2
57 ; Function Attrs: nounwind readnone speculatable
58 declare void @llvm.dbg.value(metadata, metadata, metadata) #1
60 attributes #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" }
61 attributes #1 = { nounwind readnone speculatable }
62 attributes #2 = { argmemonly nounwind }
63 attributes #3 = { nounwind readnone }
64 attributes #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" }
65 attributes #5 = { nounwind }
68 !llvm.module.flags = !{!10, !11, !12}
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")
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)
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)
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)
91 !20 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !18, file: !1, line: 2, baseType: !8, size: 32)
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)
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)