1 ; RUN: opt -O2 %s | llvm-dis > %t1
2 ; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s
3 ; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s
5 ; typedef struct v3 { int a; int b; } __v3;
6 ; #define _(x) (__builtin_preserve_access_index(x))
7 ; int get_value(const int *arg);
8 ; __v3 g __attribute__((section("stats")));
10 ; return get_value(_(&g.b));
13 ; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c
17 %struct.v3 = type { i32, i32 }
19 @g = dso_local global %struct.v3 zeroinitializer, section "stats", align 4, !dbg !0
21 ; Function Attrs: nounwind
22 define dso_local i32 @test() local_unnamed_addr #0 !dbg !16 {
24 %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.v3s(ptr elementtype(%struct.v3) nonnull @g, i32 1, i32 1), !dbg !19, !llvm.preserve.access.index !7
25 %call = tail call i32 @get_value(ptr %0) #3, !dbg !20
26 ret i32 %call, !dbg !21
32 ; CHECK: call get_value
34 ; CHECK: .long 16 # BTF_KIND_STRUCT(id = [[TID1:[0-9]+]])
36 ; CHECK: .ascii ".text" # string offset=10
37 ; CHECK: .ascii "v3" # string offset=16
38 ; CHECK: .ascii "0:1" # string offset=23
40 ; CHECK: .long 16 # FieldReloc
41 ; CHECK-NEXT: .long 10 # Field reloc section string offset=10
43 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
44 ; CHECK-NEXT: .long [[TID1]]
45 ; CHECK-NEXT: .long 23
48 declare dso_local i32 @get_value(ptr) local_unnamed_addr #1
50 ; Function Attrs: nounwind readnone
51 declare ptr @llvm.preserve.struct.access.index.p0.p0.v3s(ptr, i32, i32) #2
53 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" }
54 attributes #1 = { "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" }
55 attributes #2 = { nounwind readnone }
56 attributes #3 = { nounwind }
59 !llvm.module.flags = !{!12, !13, !14}
62 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
63 !1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !6, isLocal: false, isDefinition: true)
64 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
65 !3 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/cast")
68 !6 = !DIDerivedType(tag: DW_TAG_typedef, name: "__v3", file: !3, line: 1, baseType: !7)
69 !7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v3", file: !3, line: 1, size: 64, elements: !8)
71 !9 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !7, file: !3, line: 1, baseType: !10, size: 32)
72 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
73 !11 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !7, file: !3, line: 1, baseType: !10, size: 32, offset: 32)
74 !12 = !{i32 2, !"Dwarf Version", i32 4}
75 !13 = !{i32 2, !"Debug Info Version", i32 3}
76 !14 = !{i32 1, !"wchar_size", i32 4}
77 !15 = !{!"clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)"}
78 !16 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 5, type: !17, scopeLine: 5, isDefinition: true, isOptimized: true, unit: !2, retainedNodes: !4)
79 !17 = !DISubroutineType(types: !18)
81 !19 = !DILocation(line: 6, column: 20, scope: !16)
82 !20 = !DILocation(line: 6, column: 10, scope: !16)
83 !21 = !DILocation(line: 6, column: 3, scope: !16)