1 ; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel -experimental-debug-variable-locations=false \
2 ; RUN: | FileCheck %s --check-prefix=NORMAL \
3 ; RUN: --implicit-check-not=debug-instr-number \
4 ; RUN: --implicit-check-not=DBG_INSTR_REF
5 ; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \
6 ; RUN: -experimental-debug-variable-locations -verify-machineinstrs \
7 ; RUN: | FileCheck %s --check-prefix=INSTRREF \
8 ; RUN: --implicit-check-not=DBG_VALUE
9 ; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \
10 ; RUN: -experimental-debug-variable-locations -verify-machineinstrs \
12 ; RUN: | FileCheck %s --check-prefix=FASTISEL-INSTRREF \
13 ; RUN: --implicit-check-not=DBG_VALUE
15 ; NORMAL: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks",
16 ; NORMAL: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees",
17 ; INSTRREF: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks",
18 ; INSTRREF: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees",
19 ; FASTISEL-INSTRREF: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks",
20 ; FASTISEL-INSTRREF: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees",
22 ; Test that SelectionDAG produces DBG_VALUEs normally, but DBG_INSTR_REFs when
25 ; NORMAL-LABEL: name: foo
27 ; NORMAL: %[[REG0:[0-9]+]]:gr32 = ADD32rr
28 ; NORMAL-NEXT: DBG_VALUE %[[REG0]]
29 ; NORMAL-NEXT: DBG_VALUE_LIST {{.+}}, %[[REG0]], 2
30 ; NORMAL-NEXT: %[[REG1:[0-9]+]]:gr32 = ADD32rr
31 ; NORMAL-NEXT: DBG_VALUE %[[REG1]]
32 ; NORMAL-NEXT: DBG_VALUE_LIST {{.+}}, %[[REG1]], %[[REG0]]
34 ; Note that I'm baking in an assumption of one-based ordering here. We could
35 ; capture and check for the instruction numbers, we'd rely on machine verifier
36 ; ensuring there were no duplicates.
38 ; INSTRREF-LABEL: name: foo
41 ; INSTRREF-SAME: debug-instr-number 1
42 ; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)
43 ; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0), 2
44 ; INSTRREF-NEXT: ADD32rr
45 ; INSTRREF-SAME: debug-instr-number 2
46 ; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
47 ; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0), dbg-instr-ref(1, 0)
49 ; Test that fast-isel will produce DBG_INSTR_REFs too, except for debug values
50 ; using DIArgList, which is not supported in FastIsel.
52 ; FASTISEL-INSTRREF-LABEL: name: foo
54 ; FASTISEL-INSTRREF: ADD32rr
55 ; FASTISEL-INSTRREF-SAME: debug-instr-number 1
56 ; FASTISEL-INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)
57 ; FASTISEL-INSTRREF-NEXT: DBG_VALUE $noreg, {{.+}}
58 ; FASTISEL-INSTRREF-NEXT: ADD32rr
59 ; FASTISEL-INSTRREF-SAME: debug-instr-number 2
60 ; FASTISEL-INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
61 ; FASTISEL-INSTRREF-NEXT: DBG_VALUE $noreg, {{.+}}
63 @glob32 = global i32 0
64 @glob16 = global i16 0
67 declare void @llvm.dbg.value(metadata, metadata, metadata)
68 declare void @llvm.dbg.declare(metadata, metadata, metadata)
70 define i32 @foo(i32 %bar, i32 %baz, i32 %qux) !dbg !7 {
72 %0 = add i32 %bar, %baz, !dbg !14
73 call void @llvm.dbg.value(metadata i32 %0, metadata !13, metadata !DIExpression()), !dbg !14
74 call void @llvm.dbg.value(metadata !DIArgList(i32 %0, i32 2), metadata !13, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !14
76 call void @llvm.dbg.value(metadata i32 %1, metadata !13, metadata !DIExpression()), !dbg !14
77 call void @llvm.dbg.value(metadata !DIArgList(i32 %1, i32 %0), metadata !13, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !14
81 ; In the code below, isel produces a large number of copies between subregisters
82 ; to represent the gradually decreasing width of the argument. This gets
83 ; optimized away into three stores, but it's an objective of the instruction
84 ; referencing design that COPYs are not numbered: they move values, not define
85 ; them. Test that nothing is numbered, and instead that appropriate
86 ; substitutions with subregister details are recorded.
88 ; NORMAL-LABEL: name: bar
90 ; NORMAL: DBG_VALUE $rdi
91 ; NORMAL-NEXT: %0:gr64_with_sub_8bit = COPY $rdi
92 ; NORMAL-NEXT: DBG_VALUE %0,
93 ; NORMAL-NEXT: %1:gr32 = COPY %0.sub_32bit,
94 ; NORMAL-NEXT: DBG_VALUE %1
95 ; NORMAL: %3:gr16 = COPY %0.sub_16bit,
96 ; NORMAL-NEXT: DBG_VALUE %3
97 ; NORMAL: %5:gr8 = COPY %0.sub_8bit,
98 ; NORMAL-NEXT: DBG_VALUE %5
100 ; INSTRREF-LABEL: name: bar
103 ; INSTRREF: debugValueSubstitutions:
104 ; INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 0, subreg: 6 }
105 ; INSTRREF-NEXT: - { srcinst: 4, srcop: 0, dstinst: 3, dstop: 0, subreg: 4 }
106 ; INSTRREF-NEXT: - { srcinst: 6, srcop: 0, dstinst: 5, dstop: 0, subreg: 1 }
108 ;; As a slight inefficiency today, multiple DBG_PHIs are created.
110 ; INSTRREF: DBG_PHI $rdi, 5
111 ; INSTRREF-NEXT: DBG_PHI $rdi, 3
112 ; INSTRREF-NEXT: DBG_PHI $rdi, 1
113 ;; Allow arguments to be specified by physreg DBG_VALUEs.
114 ; INSTRREF-NEXT: DBG_VALUE $rdi
116 ;; Don't test the location of these instr-refs, only that the three non-argument
117 ;; dbg.values become DBG_INSTR_REFs. We previously checked that these numbers
118 ;; get substituted, with appropriate subregister qualifiers.
119 ; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
120 ; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0)
121 ; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(6, 0)
123 ;; In fast-isel, we get four DBG_INSTR_REFs (compared to three and one
124 ;; DBG_VALUE with normal isel). We get additional substitutions as a result:
126 ; FASTISEL-INSTRREF: debugValueSubstitutions:
127 ; FASTISEL-INSTRREF-NEXT: - { srcinst: 3, srcop: 0, dstinst: 2, dstop: 0, subreg: 6 }
128 ; FASTISEL-INSTRREF-NEXT: - { srcinst: 5, srcop: 0, dstinst: 4, dstop: 0, subreg: 6 }
129 ; FASTISEL-INSTRREF-NEXT: - { srcinst: 6, srcop: 0, dstinst: 5, dstop: 0, subreg: 4 }
130 ; FASTISEL-INSTRREF-NEXT - { srcinst: 8, srcop: 0, dstinst: 7, dstop: 0, subreg: 6 }
131 ; FASTISEL-INSTRREF-NEXT - { srcinst: 9, srcop: 0, dstinst: 8, dstop: 0, subreg: 4 }
132 ; FASTISEL-INSTRREF-NEXT - { srcinst: 10, srcop: 0, dstinst: 9, dstop: 0, subreg: 1 }
134 ;; Those substitutions are anchored against these DBG_PHIs:
136 ; FASTISEL-INSTRREF: DBG_PHI $rdi, 7
137 ; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 4
138 ; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 2
139 ; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 1
141 ; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)
142 ; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 0)
143 ; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(6, 0)
144 ; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(10, 0)
146 define i32 @bar(i64 %bar) !dbg !20 {
148 call void @llvm.dbg.value(metadata i64 %bar, metadata !21, metadata !DIExpression()), !dbg !22
149 %0 = trunc i64 %bar to i32, !dbg !22
150 call void @llvm.dbg.value(metadata i32 %0, metadata !21, metadata !DIExpression()), !dbg !22
151 store i32 %0, ptr @glob32, !dbg !22
152 %1 = trunc i32 %0 to i16, !dbg !22
153 call void @llvm.dbg.value(metadata i16 %1, metadata !21, metadata !DIExpression()), !dbg !22
154 store i16 %1, ptr @glob16, !dbg !22
155 %2 = trunc i16 %1 to i8, !dbg !22
156 call void @llvm.dbg.value(metadata i8 %2, metadata !21, metadata !DIExpression()), !dbg !22
157 store i8 %2, ptr @glob8, !dbg !22
161 ; Ensure that we can track copies back to physreg defs, and throw in a subreg
162 ; substitution for fun. The call to @xyzzy defines $rax, which gets copied to
163 ; a VReg, and then truncated by a subreg copy. We should be able to track
164 ; through the copies and walk back to the physreg def, labelling the CALL
165 ; instruction. We should also be able to do this even when the block layout is
168 ; NORMAL-LABEL: name: baz
170 ; NORMAL: CALL64pcrel32 target-flags(x86-plt) @xyzzy
171 ; NORMAL: %2:gr64 = COPY $rax,
172 ; NORMAL: %0:gr64 = COPY %2,
173 ; NORMAL-LABEL: bb.1.slippers:
174 ; NORMAL: DBG_VALUE %1
175 ; NORMAL-LABEL: bb.2.shoes:
176 ; NORMAL: %1:gr16 = COPY %0.sub_16bit
178 ; INSTRREF-LABEL: name: baz
180 ; INSTRREF: debugValueSubstitutions:
181 ; INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 6, subreg: 4 }
183 ; INSTRREF: CALL64pcrel32 target-flags(x86-plt) @xyzzy, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $rax, debug-instr-number 1
184 ; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
186 ;; Fast-isel produces the same arrangement, a DBG_INSTR_REF pointing back to
187 ;; the call instruction. However: the operand numbers are different (6 for
188 ;; normal isel, 4 for fast-isel). This isn't because of debug-info differences,
189 ;; it's because normal isel implicit-defs the stack registers, and fast-isel
190 ;; does not. The meaning is the same.
192 ; FASTISEL-INSTRREF-LABEL: name: baz
194 ; FASTISEL-INSTRREF: debugValueSubstitutions:
195 ; FASTISEL-INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 4, subreg: 4 }
197 ; FASTISEL-INSTRREF: CALL64pcrel32 target-flags(x86-plt) @xyzzy, csr_64, implicit $rsp, implicit $ssp, implicit-def $rax, debug-instr-number 1
198 ; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
202 define i32 @baz() !dbg !30 {
204 %foo = call i64 @xyzzy(), !dbg !32
208 call void @llvm.dbg.value(metadata i16 %moo, metadata !31, metadata !DIExpression()), !dbg !32
209 store i16 %moo, ptr @glob16, !dbg !32
213 %moo = trunc i64 %foo to i16
217 ;; Test for dbg.declare of non-stack-slot Values. These turn up with NRVO and
218 ;; other ABI scenarios where something is technically in memory, but we don't
219 ;; refer to it relative to the stack pointer. We refer to these either with an
220 ;; indirect DBG_VALUE, or a DBG_INSTR_REF with DW_OP_deref prepended.
222 ;; Test an inlined dbg.declare in a different scope + block, to test behaviours
223 ;; where the debug intrinsic isn't in the first block. The normal-mode DBG_VALUE
224 ;; is hoisted into the entry block for that. This is fine because the variable
225 ;; location is never re-assigned. (FIXME: do we scope-trim / fail-to-propagate
226 ;; these hoisted locations later?).
228 ; NORMAL-LABEL: name: qux
230 ; NORMAL: DBG_VALUE $rdi, 0, ![[SOCKS]], !DIExpression(),
231 ; NORMAL-NEXT: %0:gr64 = COPY $rdi
232 ; NORMAL-NEXT: DBG_VALUE %0, 0, ![[SOCKS]], !DIExpression(),
233 ; NORMAL-NEXT: DBG_VALUE %0, 0, ![[KNEES]], !DIExpression(),
235 ;; In instruction referencing mode, the "real" argument becomes a DBG_VALUE,
236 ;; but the hoisted variable location from the inlined scope is a DBG_INSTR_REF.
238 ; INSTRREF-LABEL: name: qux
240 ; INSTRREF: DBG_PHI $rdi, 1
241 ; INSTRREF-NEXT: DBG_VALUE $rdi, 0, ![[SOCKS]], !DIExpression(),
242 ; INSTRREF-NEXT: %0:gr64 = COPY $rdi
243 ; INSTRREF-NEXT: DBG_INSTR_REF ![[KNEES]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0),
245 ; In fast-isel mode, neither variable are hoisted or forwarded to a physreg.
247 ; FASTISEL-INSTRREF-LABEL: name: qux
249 ; FASTISEL-INSTRREF: DBG_PHI $rdi, 1
250 ; FASTISEL-INSTRREF: DBG_INSTR_REF ![[SOCKS]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0),
252 ; FASTISEL-INSTRREF-LABEL: bb.1.lala:
253 ; FASTISEL-INSTRREF: DBG_INSTR_REF ![[KNEES]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0),
254 declare i64 @cheddar(ptr %arg)
256 define void @qux(ptr noalias sret(i32) %agg.result) !dbg !40 {
258 call void @llvm.dbg.declare(metadata ptr %agg.result, metadata !41, metadata !DIExpression()), !dbg !42
259 %foo = call i64 @cheddar(ptr %agg.result), !dbg !42
263 call void @llvm.dbg.declare(metadata ptr %agg.result, metadata !45, metadata !DIExpression()), !dbg !44
270 !llvm.module.flags = !{!3, !4}
272 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
273 !1 = !DIFile(filename: "exprconflict.c", directory: "/home/jmorse")
275 !3 = !{i32 2, !"Dwarf Version", i32 4}
276 !4 = !{i32 2, !"Debug Info Version", i32 3}
277 !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
278 !8 = !DISubroutineType(types: !9)
280 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
282 !13 = !DILocalVariable(name: "baz", scope: !7, file: !1, line: 6, type: !10)
283 !14 = !DILocation(line: 1, scope: !7)
284 !20 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
285 !21 = !DILocalVariable(name: "xyzzy", scope: !20, file: !1, line: 6, type: !10)
286 !22 = !DILocation(line: 1, scope: !20)
287 !30 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
288 !31 = !DILocalVariable(name: "xyzzy", scope: !30, file: !1, line: 6, type: !10)
289 !32 = !DILocation(line: 1, scope: !30)
290 !40 = distinct !DISubprogram(name: "qux", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
291 !41 = !DILocalVariable(name: "socks", scope: !40, file: !1, line: 6, type: !10)
292 !42 = !DILocation(line: 1, scope: !40)
293 !43 = distinct !DISubprogram(name: "inlined", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
294 !44 = !DILocation(line: 0, scope: !43, inlinedAt: !42)
295 !45 = !DILocalVariable(name: "knees", scope: !43, file: !1, line: 6, type: !10)