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
3
4; Source code:
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); }
11; Compilation flag:
12;   clang -target bpf -O2 -g -S -emit-llvm test.c
13
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
18
19; Function Attrs: norecurse nounwind
20define 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
34  ret i64 %13, !dbg !40
35}
36
37; CHECK:             .section        .BTF,"",@progbits
38; CHECK-NEXT:        .short  60319                   # 0xeb9f
39; CHECK-NEXT:        .byte   1
40; CHECK-NEXT:        .byte   0
41; CHECK-NEXT:        .long   24
42; CHECK-NEXT:        .long   0
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
48; CHECK-NEXT:        .long   2
49; CHECK-NEXT:        .long   1                       # BTF_KIND_INT(id = 2)
50; CHECK-NEXT:        .long   16777216                # 0x1000000
51; CHECK-NEXT:        .long   8
52; CHECK-NEXT:        .long   16777280                # 0x1000040
53; CHECK-NEXT:        .long   10                      # BTF_KIND_FUNC(id = 3)
54; CHECK-NEXT:        .long   201326593               # 0xc000001
55; CHECK-NEXT:        .long   1
56; CHECK-NEXT:        .long   0                       # BTF_KIND_VOLATILE(id = 4)
57; CHECK-NEXT:        .long   150994944               # 0x9000000
58; CHECK-NEXT:        .long   5
59; CHECK-NEXT:        .long   0                       # BTF_KIND_PTR(id = 5)
60; CHECK-NEXT:        .long   33554432                # 0x2000000
61; CHECK-NEXT:        .long   6
62; CHECK-NEXT:        .long   58                      # BTF_KIND_INT(id = 6)
63; CHECK-NEXT:        .long   16777216                # 0x1000000
64; CHECK-NEXT:        .long   4
65; CHECK-NEXT:        .long   16777248                # 0x1000020
66; CHECK-NEXT:        .long   62                      # BTF_KIND_VAR(id = 7)
67; CHECK-NEXT:        .long   234881024               # 0xe000000
68; CHECK-NEXT:        .long   4
69; CHECK-NEXT:        .long   0
70; CHECK-NEXT:        .long   0                       # BTF_KIND_VOLATILE(id = 8)
71; CHECK-NEXT:        .long   150994944               # 0x9000000
72; CHECK-NEXT:        .long   9
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
78; CHECK-NEXT:        .long   6
79; CHECK-NEXT:        .long   65                      # BTF_KIND_VAR(id = 11)
80; CHECK-NEXT:        .long   234881024               # 0xe000000
81; CHECK-NEXT:        .long   8
82; CHECK-NEXT:        .long   0
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
88; CHECK-NEXT:        .long   5
89; CHECK-NEXT:        .long   76                      # BTF_KIND_VAR(id = 14)
90; CHECK-NEXT:        .long   234881024               # 0xe000000
91; CHECK-NEXT:        .long   12
92; CHECK-NEXT:        .long   0
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
99; CHECK-NEXT:        .long   0
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
143
144attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "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" }
145
146!llvm.dbg.cu = !{!2}
147!llvm.module.flags = !{!23, !24, !25}
148!llvm.ident = !{!26}
149
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")
154!4 = !{}
155!5 = !{!6}
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)
191