1 ; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
2 ; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
5 ; typedef int * int_ptr;
6 ; static int * volatile v1;
7 ; static const int * volatile v2;
8 ; static volatile int_ptr v3 = 0;
9 ; static volatile const int_ptr v4 = 0;
10 ; long foo() { return (long)(v1 - v2 + v3 - v4); }
12 ; clang -target bpf -O2 -g -S -emit-llvm test.c
14 @v1 = internal global i32* null, align 8, !dbg !0
15 @v2 = internal global i32* null, align 8, !dbg !8
16 @v3 = internal global i32* null, align 8, !dbg !14
17 @v4 = internal constant i32* null, align 8, !dbg !19
19 ; Function Attrs: norecurse nounwind
20 define dso_local i64 @foo() local_unnamed_addr #0 !dbg !27 {
21 %1 = load volatile i32*, i32** @v1, align 8, !dbg !29, !tbaa !30
22 %2 = load volatile i32*, i32** @v2, align 8, !dbg !34, !tbaa !30
23 %3 = ptrtoint i32* %1 to i64, !dbg !35
24 %4 = ptrtoint i32* %2 to i64, !dbg !35
25 %5 = sub i64 %3, %4, !dbg !35
26 %6 = ashr exact i64 %5, 2, !dbg !35
27 %7 = load volatile i32*, i32** @v3, align 8, !dbg !36, !tbaa !30
28 %8 = getelementptr inbounds i32, i32* %7, i64 %6, !dbg !37
29 %9 = load volatile i32*, i32** @v4, align 8, !dbg !38, !tbaa !30
30 %10 = ptrtoint i32* %8 to i64, !dbg !39
31 %11 = ptrtoint i32* %9 to i64, !dbg !39
32 %12 = sub i64 %10, %11, !dbg !39
33 %13 = ashr exact i64 %12, 2, !dbg !39
37 ; CHECK: .section .BTF,"",@progbits
38 ; CHECK-NEXT: .short 60319 # 0xeb9f
41 ; CHECK-NEXT: .long 24
43 ; CHECK-NEXT: .long 288
44 ; CHECK-NEXT: .long 288
45 ; CHECK-NEXT: .long 95
46 ; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
47 ; CHECK-NEXT: .long 218103808 # 0xd000000
49 ; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
50 ; CHECK-NEXT: .long 16777216 # 0x1000000
52 ; CHECK-NEXT: .long 16777280 # 0x1000040
53 ; CHECK-NEXT: .long 10 # BTF_KIND_FUNC(id = 3)
54 ; CHECK-NEXT: .long 201326592 # 0xc000000
56 ; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4)
57 ; CHECK-NEXT: .long 150994944 # 0x9000000
59 ; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 5)
60 ; CHECK-NEXT: .long 33554432 # 0x2000000
62 ; CHECK-NEXT: .long 58 # BTF_KIND_INT(id = 6)
63 ; CHECK-NEXT: .long 16777216 # 0x1000000
65 ; CHECK-NEXT: .long 16777248 # 0x1000020
66 ; CHECK-NEXT: .long 62 # BTF_KIND_VAR(id = 7)
67 ; CHECK-NEXT: .long 234881024 # 0xe000000
70 ; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 8)
71 ; CHECK-NEXT: .long 150994944 # 0x9000000
73 ; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 9)
74 ; CHECK-NEXT: .long 33554432 # 0x2000000
75 ; CHECK-NEXT: .long 10
76 ; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 10)
77 ; CHECK-NEXT: .long 167772160 # 0xa000000
79 ; CHECK-NEXT: .long 65 # BTF_KIND_VAR(id = 11)
80 ; CHECK-NEXT: .long 234881024 # 0xe000000
83 ; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 12)
84 ; CHECK-NEXT: .long 150994944 # 0x9000000
85 ; CHECK-NEXT: .long 13
86 ; CHECK-NEXT: .long 68 # BTF_KIND_TYPEDEF(id = 13)
87 ; CHECK-NEXT: .long 134217728 # 0x8000000
89 ; CHECK-NEXT: .long 76 # BTF_KIND_VAR(id = 14)
90 ; CHECK-NEXT: .long 234881024 # 0xe000000
91 ; CHECK-NEXT: .long 12
93 ; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 15)
94 ; CHECK-NEXT: .long 167772160 # 0xa000000
95 ; CHECK-NEXT: .long 12
96 ; CHECK-NEXT: .long 79 # BTF_KIND_VAR(id = 16)
97 ; CHECK-NEXT: .long 234881024 # 0xe000000
98 ; CHECK-NEXT: .long 15
100 ; CHECK-NEXT: .long 82 # BTF_KIND_DATASEC(id = 17)
101 ; CHECK-NEXT: .long 251658243 # 0xf000003
102 ; CHECK-NEXT: .long 0
103 ; CHECK-NEXT: .long 7
104 ; CHECK-NEXT: .long v1
105 ; CHECK-NEXT: .long 8
106 ; CHECK-NEXT: .long 11
107 ; CHECK-NEXT: .long v2
108 ; CHECK-NEXT: .long 8
109 ; CHECK-NEXT: .long 14
110 ; CHECK-NEXT: .long v3
111 ; CHECK-NEXT: .long 8
112 ; CHECK-NEXT: .long 87 # BTF_KIND_DATASEC(id = 18)
113 ; CHECK-NEXT: .long 251658241 # 0xf000001
114 ; CHECK-NEXT: .long 0
115 ; CHECK-NEXT: .long 16
116 ; CHECK-NEXT: .long v4
117 ; CHECK-NEXT: .long 8
118 ; CHECK-NEXT: .byte 0 # string offset=0
119 ; CHECK-NEXT: .ascii "long int" # string offset=1
120 ; CHECK-NEXT: .byte 0
121 ; CHECK-NEXT: .ascii "foo" # string offset=10
122 ; CHECK-NEXT: .byte 0
123 ; CHECK-NEXT: .ascii ".text" # string offset=14
124 ; CHECK-NEXT: .byte 0
125 ; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bugs/test.c" # string offset=20
126 ; CHECK-NEXT: .byte 0
127 ; CHECK-NEXT: .ascii "int" # string offset=58
128 ; CHECK-NEXT: .byte 0
129 ; CHECK-NEXT: .ascii "v1" # string offset=62
130 ; CHECK-NEXT: .byte 0
131 ; CHECK-NEXT: .ascii "v2" # string offset=65
132 ; CHECK-NEXT: .byte 0
133 ; CHECK-NEXT: .ascii "int_ptr" # string offset=68
134 ; CHECK-NEXT: .byte 0
135 ; CHECK-NEXT: .ascii "v3" # string offset=76
136 ; CHECK-NEXT: .byte 0
137 ; CHECK-NEXT: .ascii "v4" # string offset=79
138 ; CHECK-NEXT: .byte 0
139 ; CHECK-NEXT: .ascii ".bss" # string offset=82
140 ; CHECK-NEXT: .byte 0
141 ; CHECK-NEXT: .ascii ".rodata" # string offset=87
142 ; CHECK-NEXT: .byte 0
144 attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" }
147 !llvm.module.flags = !{!23, !24, !25}
150 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
151 !1 = distinct !DIGlobalVariable(name: "v1", scope: !2, file: !3, line: 2, type: !22, isLocal: true, isDefinition: true)
152 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !7, nameTableKind: None)
153 !3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bugs")
156 !6 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
157 !7 = !{!0, !8, !14, !19}
158 !8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
159 !9 = distinct !DIGlobalVariable(name: "v2", scope: !2, file: !3, line: 3, type: !10, isLocal: true, isDefinition: true)
160 !10 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !11)
161 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
162 !12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13)
163 !13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
164 !14 = !DIGlobalVariableExpression(var: !15, expr: !DIExpression())
165 !15 = distinct !DIGlobalVariable(name: "v3", scope: !2, file: !3, line: 4, type: !16, isLocal: true, isDefinition: true)
166 !16 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !17)
167 !17 = !DIDerivedType(tag: DW_TAG_typedef, name: "int_ptr", file: !3, line: 1, baseType: !18)
168 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
169 !19 = !DIGlobalVariableExpression(var: !20, expr: !DIExpression())
170 !20 = distinct !DIGlobalVariable(name: "v4", scope: !2, file: !3, line: 5, type: !21, isLocal: true, isDefinition: true)
171 !21 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !16)
172 !22 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !18)
173 !23 = !{i32 2, !"Dwarf Version", i32 4}
174 !24 = !{i32 2, !"Debug Info Version", i32 3}
175 !25 = !{i32 1, !"wchar_size", i32 4}
176 !26 = !{!"clang version 8.0.20181009 "}
177 !27 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 6, type: !28, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: true, unit: !2, retainedNodes: !4)
178 !28 = !DISubroutineType(types: !5)
179 !29 = !DILocation(line: 6, column: 28, scope: !27)
180 !30 = !{!31, !31, i64 0}
181 !31 = !{!"any pointer", !32, i64 0}
182 !32 = !{!"omnipotent char", !33, i64 0}
183 !33 = !{!"Simple C/C++ TBAA"}
184 !34 = !DILocation(line: 6, column: 33, scope: !27)
185 !35 = !DILocation(line: 6, column: 31, scope: !27)
186 !36 = !DILocation(line: 6, column: 38, scope: !27)
187 !37 = !DILocation(line: 6, column: 36, scope: !27)
188 !38 = !DILocation(line: 6, column: 43, scope: !27)
189 !39 = !DILocation(line: 6, column: 41, scope: !27)
190 !40 = !DILocation(line: 6, column: 14, scope: !27)