1--- |
2  ; RUN: llc %s -march=x86-64 -run-pass=livedebugvalues -o - -experimental-debug-variable-locations | FileCheck %s -implicit-check-not=DBG_VALUE
3
4  ; The MIR below represents a pathalogical case for value-tracking
5  ; LiveDebugValues. The code structure is eight nested loops, with loop heads
6  ; from bb.1 to bb.8, a central block bb.9 that does nothing, and loop ends
7  ; from bb.10 to bb.17. The CMP's and jumps might be broken; the only
8  ; important part is that it looks like nested loops to LiveDebugValues.
9  ;
10  ; The variable location is always $rsi, which enters the function live.
11  ; There's also a def of $rsi in bb.14, in a loop tail, half way into the
12  ; loop nest.s.
13  ;
14  ; This presents a serious problem: the outer four loops each implicitly have
15  ; a PHI value for $rsi, because the block could be entered on a path straight
16  ; from entry, or from bb.14 where $rsi is def'd. While the innermost four
17  ; loops have a value of $rsi that is live-through each loop from bb.5
18  ; onwards.
19  ;
20  ; Value-tracking LiveDebugValues _must_ correctly identify each PHI value.
21  ; Observe the DBG_VALUE in bb.2: this variable location musn't be propagated
22  ; any further, because there's a path to either successor that goes through
23  ; bb.14 where the value is overwritten.Value tracking needs to identify the
24  ; PHI value on entry to the block; and that each successor has a different
25  ; PHI value in that register.
26  ;
27  ; Likewise, we mustn't identify values as PHIs which aren't. Entering bb.5
28  ; has a PHI value (from bb.4) in $rsi. There are no paths to bb.5 that pass
29  ; through the clobbering bb.14, which don't also pass through bb.4: thus
30  ; that value is live-through the innermost four loops. If we
31  ; over-approximated where PHIs happened, we would lose variable location
32  ; coverage here, by not propagating the variable location through the inner
33  ; loops.
34  ;
35  ; Getting this right requires the lattice descent (described in the
36  ; implementation) to search loop head PHI values, until one is found that is
37  ; live-through a loop.
38
39  ; This location in bb.2 should not be propagated further,
40  ; CHECK-LABEL: bb.2:
41  ; CHECK:  DBG_VALUE $rsi, $noreg
42
43  ; This location should be live through the inner loops, til bb.14
44  ; CHECK-LABEL: bb.5:
45  ; CHECK:  DBG_VALUE $rsi, $noreg
46  ; CHECK-LABEL: bb.6:
47  ; CHECK:  DBG_VALUE $rsi, $noreg
48  ; CHECK-LABEL: bb.7:
49  ; CHECK:  DBG_VALUE $rsi, $noreg
50  ; CHECK-LABEL: bb.8:
51  ; CHECK:  DBG_VALUE $rsi, $noreg
52  ; CHECK-LABEL: bb.9:
53  ; CHECK:  DBG_VALUE $rsi, $noreg
54  ; CHECK-LABEL: bb.10:
55  ; CHECK:  DBG_VALUE $rsi, $noreg
56  ; CHECK-LABEL: bb.11:
57  ; CHECK:  DBG_VALUE $rsi, $noreg
58  ; CHECK-LABEL: bb.12:
59  ; CHECK:  DBG_VALUE $rsi, $noreg
60  ; CHECK-LABEL: bb.13:
61  ; CHECK:  DBG_VALUE $rsi, $noreg
62
63  declare i64 @bees(i64 %arg);
64
65  define i32 @chiasm(i64 %arg) local_unnamed_addr !dbg !12 {
66  entry:
67    br label %bb1, !dbg !17
68  bb1:
69    br label %bb2, !dbg !17
70  bb2:
71    br label %bb3, !dbg !17
72  bb3:
73    ret i32 0, !dbg !17
74  }
75
76  !llvm.dbg.cu = !{!0}
77  !llvm.module.flags = !{!7, !8, !9, !10}
78  !llvm.ident = !{!11}
79  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, debugInfoForProfiling: true, nameTableKind: None)
80  !1 = !DIFile(filename: "main.cpp", directory: "F:\")
81  !2 = !{}
82  !3 = !{!4}
83  !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
84  !5 = distinct !DIGlobalVariable(name: "start", scope: !0, file: !1, line: 4, type: !6, isLocal: false, isDefinition: true)
85  !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
86  !7 = !{i32 2, !"Dwarf Version", i32 4}
87  !8 = !{i32 2, !"Debug Info Version", i32 3}
88  !9 = !{i32 1, !"wchar_size", i32 2}
89  !10 = !{i32 7, !"PIC Level", i32 2}
90  !11 = !{!"clang version 10.0.0"}
91  !12 = distinct !DISubprogram(name: "bb_to_bb", linkageName: "bb_to_bb", scope: !1, file: !1, line: 6, type: !13, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15)
92  !13 = !DISubroutineType(types: !14)
93  !14 = !{!6, !6}
94  !15 = !{!16}
95  !16 = !DILocalVariable(name: "myVar", scope: !12, file: !1, line: 7, type: !6)
96  !17 = !DILocation(line: 10, scope: !12)
97
98...
99---
100name: chiasm
101tracksRegLiveness: true
102liveins:
103  - { reg: '$rdi', virtual-reg: '' }
104stack:
105  - { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
106      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
107      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
108body:  |
109  bb.0.entry:
110  liveins: $rdi, $rsi
111
112  bb.1:
113  liveins: $rsi, $rdi
114    CMP64ri8 renamable $rdi, 1, implicit-def $eflags, debug-location !17
115    JCC_1 %bb.17, 4, implicit $eflags, debug-location !17
116
117  bb.2:
118  liveins: $rsi, $rdi
119    DBG_VALUE $rsi, $noreg, !16, !DIExpression(), debug-location !17
120    CMP64ri8 renamable $rdi, 2, implicit-def $eflags, debug-location !17
121    JCC_1 %bb.16, 4, implicit $eflags, debug-location !17
122
123  bb.3:
124  liveins: $rsi, $rdi
125    CMP64ri8 renamable $rdi, 3, implicit-def $eflags, debug-location !17
126    JCC_1 %bb.15, 4, implicit $eflags, debug-location !17
127
128  bb.4:
129  liveins: $rsi, $rdi
130    CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
131    JCC_1 %bb.14, 4, implicit $eflags, debug-location !17
132
133  bb.5:
134  liveins: $rsi, $rdi
135    DBG_VALUE $rsi, $noreg, !16, !DIExpression(), debug-location !17
136    CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
137    JCC_1 %bb.13, 4, implicit $eflags, debug-location !17
138
139  bb.6:
140  liveins: $rsi, $rdi
141    CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
142    JCC_1 %bb.12, 4, implicit $eflags, debug-location !17
143
144  bb.7:
145  liveins: $rsi, $rdi
146    CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
147    JCC_1 %bb.11, 4, implicit $eflags, debug-location !17
148
149  bb.8:
150  liveins: $rsi, $rdi
151    CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
152    JCC_1 %bb.10, 4, implicit $eflags, debug-location !17
153
154  bb.9:
155  liveins: $rsi, $rdi, $eflags
156    ;$rsi = MOV64ri 0, debug-location !17
157    ;JMP_1 %bb.1, debug-location !17
158
159  bb.10:
160  liveins: $rsi, $rdi, $eflags
161    JCC_1 %bb.8, 4, implicit $eflags, debug-location !17
162
163  bb.11:
164  liveins: $rsi, $rdi, $eflags
165    JCC_1 %bb.7, 4, implicit $eflags, debug-location !17
166
167  bb.12:
168  liveins: $rsi, $rdi, $eflags
169    JCC_1 %bb.6, 4, implicit $eflags, debug-location !17
170
171  bb.13:
172  liveins: $rsi, $rdi, $eflags
173    JCC_1 %bb.5, 4, implicit $eflags, debug-location !17
174
175  bb.14:
176  liveins: $rsi, $rdi, $eflags
177    $rsi = MOV64ri 0, debug-location !17
178    JCC_1 %bb.4, 4, implicit $eflags, debug-location !17
179
180  bb.15:
181  liveins: $rsi, $rdi, $eflags
182    JCC_1 %bb.3, 4, implicit $eflags, debug-location !17
183
184  bb.16:
185  liveins: $rsi, $rdi, $eflags
186    JCC_1 %bb.2, 4, implicit $eflags, debug-location !17
187
188  bb.17:
189  liveins: $rsi, $rdi, $eflags
190    JCC_1 %bb.1, 4, implicit $eflags, debug-location !17
191
192  bb.18:
193  liveins: $rsi, $rdi, $eflags
194    RETQ
195
196...
197