llvm.org GIT mirror llvm / db1b5f0
[CodeGen] Avoid handling DBG_VALUE in the LivePhysRegs (addUses,removeDefs,stepForward) Summary: This patch prevents DBG_VALUE instructions from influencing LivePhysRegs::stepBackwards and stepForwards. In at least one case, specifically branch folding, the stepBackwards logic was having an influence on code generation. The result was that certain code compiled with '-g -O2' would differ from that compiled with '-O2' alone. It seems that the original logic, accounting for DBG_VALUE, was influencing the placement of an IMPLICIT_DEF which had a later impact on how blocks were processed in branch folding. Reviewers: kparzysz, MatzeB Reviewed By: kparzysz Subscribers: bjope, llvm-commits Tags: #debug-info Differential Revision: https://reviews.llvm.org/D43850 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327862 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Davis 1 year, 11 months ago
2 changed file(s) with 216 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
4343 void LivePhysRegs::removeDefs(const MachineInstr &MI) {
4444 for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
4545 if (O->isReg()) {
46 if (!O->isDef())
46 if (!O->isDef() || O->isDebug())
4747 continue;
4848 unsigned Reg = O->getReg();
4949 if (!TargetRegisterInfo::isPhysicalRegister(Reg))
5757 /// Add uses to the set.
5858 void LivePhysRegs::addUses(const MachineInstr &MI) {
5959 for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
60 if (!O->isReg() || !O->readsReg())
60 if (!O->isReg() || !O->readsReg() || O->isDebug())
6161 continue;
6262 unsigned Reg = O->getReg();
6363 if (!TargetRegisterInfo::isPhysicalRegister(Reg))
8484 SmallVectorImpl> &Clobbers) {
8585 // Remove killed registers from the set.
8686 for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
87 if (O->isReg()) {
87 if (O->isReg() && !O->isDebug()) {
8888 unsigned Reg = O->getReg();
8989 if (!TargetRegisterInfo::isPhysicalRegister(Reg))
9090 continue;
0 # RUN: llc -run-pass=block-placement %s -o - | FileCheck %s
1
2 --- |
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
5
6 define void @_Z3fn1v() !dbg !6 {
7 entry:
8 %d = alloca i8, align 1
9 br i1 1, label %for.cond.cleanup, label %for.body
10
11 for.cond.cleanup:
12 ret void
13
14 for.body:
15 br i1 1, label %for.cond.cleanup, label %for.body.1
16
17 for.body.1:
18 br i1 1, label %for.cond.cleanup, label %for.body.2
19
20 for.body.2:
21 br i1 1, label %for.cond.cleanup, label %for.body.3
22
23 for.body.3:
24 br i1 1, label %for.cond.cleanup, label %for.body.4
25
26 for.body.4:
27 br i1 1, label %for.cond.cleanup, label %for.body.5
28
29 for.body.5:
30 br i1 1, label %for.cond.cleanup, label %for.body.6
31
32 for.body.6:
33 br i1 1, label %for.cond.cleanup, label %for.body.7
34
35 for.body.7:
36 br i1 1, label %for.cond.cleanup, label %for.body.8
37
38 for.body.8:
39 br i1 1, label %for.cond.cleanup, label %for.body.9
40
41 for.body.9:
42 br i1 1, label %for.cond.cleanup, label %for.body.10
43
44 for.body.10:
45 br i1 1, label %for.cond.cleanup, label %for.body.11
46
47 for.body.11:
48 %d.0.d.0..12 = load volatile i8, i8* %d, align 1
49 call void @llvm.dbg.value(metadata i8 %d.0.d.0..12, metadata !16, metadata !DIExpression()), !dbg !19
50 br label %for.cond.cleanup
51 }
52
53 declare void @llvm.dbg.value(metadata, metadata, metadata)
54
55 !llvm.dbg.cu = !{!0}
56 !llvm.module.flags = !{!3, !4, !5}
57
58 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 7.0.0 (trunk 326606)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2)
59 !1 = !DIFile(filename: "repro.cpp", directory: "/home/mdavis/bugs/bz-189869")
60 !2 = !{}
61 !3 = !{i32 2, !"Dwarf Version", i32 4}
62 !4 = !{i32 2, !"Debug Info Version", i32 3}
63 !5 = !{i32 1, !"wchar_size", i32 4}
64 !6 = distinct !DISubprogram(name: "fn1", linkageName: "_Z3fn1v", scope: !7, file: !7, line: 4, type: !8, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !15)
65 !7 = !DIFile(filename: "./repro.cpp", directory: "/home/mdavis/bugs/bz-189869")
66 !8 = !DISubroutineType(types: !9)
67 !9 = !{}
68 !15 = !{!16}
69 !16 = !DILocalVariable(name: "d", scope: !6, file: !7, line: 6, type: !17)
70 !17 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !18)
71 !18 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
72 !19 = !DILocation(line: 6, column: 17, scope: !6)
73
74 ...
75 ---
76 # CHECK: name: _Z3fn1v
77 # CHECK: bb.10.for.body.9
78 # CHECK: renamable $al
79 # CHECK-NEXT: TEST8rr killed renamable $al
80 # CHECK-NEXT: JNE_1
81 # CHECK-NOT: $al = IMPLICIT_DEF
82 # CHECK: bb.12.for.body.10
83
84 name: _Z3fn1v
85 alignment: 4
86 tracksRegLiveness: true
87 constants:
88 body: |
89 bb.0.entry:
90 successors: %bb.1, %bb.4
91 liveins: $rdi, $rbp, $r15, $r14, $r13, $r12, $rbx
92
93 renamable $al = MOV8ri 1
94 TEST8rr renamable $al, renamable $al, implicit-def $eflags
95 JNE_1 %bb.4, implicit killed $eflags
96
97 bb.1.for.cond.cleanup:
98 successors: %bb.3, %bb.2
99 liveins: $ecx, $rdi
100
101 renamable $eax = MOV32rm $rsp, 1, $noreg, -16, $noreg
102 CMP32rm killed renamable $eax, $rip, 1, $noreg, $noreg, $noreg, implicit-def $eflags
103 JBE_1 %bb.3, implicit $eflags
104
105 bb.2:
106 successors: %bb.3
107 liveins: $ebp, $ebx, $edx, $esi, $rdi, $r8d, $r9d, $r10d, $r11d, $r12d, $r13d, $r14d, $r15d
108
109 bb.3.for.cond.cleanup:
110 liveins: $rdi, $xmm3, $xmm4, $xmm5, $xmm6, $xmm7, $xmm9, $xmm13, $xmm14
111 RETQ
112
113 bb.4.for.body:
114 successors: %bb.1, %bb.5
115 liveins: $al, $rdi
116
117 renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags
118 TEST8rr killed renamable $al, renamable $al, implicit-def $eflags
119 JNE_1 %bb.1, implicit $eflags
120
121 bb.5.for.body.1:
122 successors: %bb.1, %bb.6
123 liveins: $ecx, $rdi
124
125 renamable $al = MOV8ri 1
126 TEST8rr killed renamable $al, renamable $al, implicit-def $eflags
127 JNE_1 %bb.1, implicit $eflags
128
129 bb.6.for.body.2:
130 successors: %bb.1, %bb.7
131 liveins: $ecx, $eflags, $rdi
132
133 JNE_1 %bb.1, implicit $eflags
134
135 bb.7.for.body.3:
136 successors: %bb.1, %bb.8
137 liveins: $ecx, $rdi
138
139 renamable $al = MOV8ri 1
140 TEST8rr killed renamable $al, renamable $al, implicit-def $eflags
141 JNE_1 %bb.1, implicit $eflags
142
143 bb.8.for.body.4:
144 successors: %bb.1, %bb.9
145 liveins: $ecx, $eflags, $rdi
146
147 JNE_1 %bb.1, implicit $eflags
148
149 bb.9.for.body.5:
150 successors: %bb.1, %bb.10
151 liveins: $ecx, $rdi
152
153 renamable $al = MOV8ri 1
154 TEST8rr killed renamable $al, renamable $al, implicit-def $eflags
155 JNE_1 %bb.1, implicit $eflags
156
157 bb.10.for.body.6:
158 successors: %bb.1, %bb.11
159 liveins: $ecx, $eflags, $rdi
160
161 JNE_1 %bb.1, implicit $eflags
162
163 bb.11.for.body.7:
164 successors: %bb.1, %bb.12
165 liveins: $ecx, $rdi
166
167 renamable $al = MOV8ri 1
168 TEST8rr killed renamable $al, renamable $al, implicit-def $eflags
169 JNE_1 %bb.1, implicit $eflags
170
171 bb.12.for.body.8:
172 successors: %bb.1, %bb.13
173 liveins: $ecx, $eflags, $rdi
174
175 JNE_1 %bb.1, implicit $eflags
176
177 bb.13.for.body.9:
178 successors: %bb.14, %bb.15
179 liveins: $rdi
180
181 renamable $al = MOV8ri 1
182 TEST8rr killed renamable $al, renamable $al, implicit-def $eflags
183 JE_1 %bb.15, implicit $eflags
184
185 bb.14:
186 successors: %bb.1
187 liveins: $rdi
188
189 renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags
190 JMP_1 %bb.1
191
192 bb.15.for.body.10:
193 successors: %bb.16, %bb.17
194 liveins: $eflags, $rdi
195
196 JE_1 %bb.17, implicit killed $eflags
197
198 bb.16:
199 successors: %bb.1
200 liveins: $rdi
201
202 JMP_1 %bb.1
203
204 bb.17.for.body.11:
205 successors: %bb.1
206 liveins: $rdi
207
208 dead renamable $al = MOV8rm $rsp, 1, $noreg, -121, $noreg
209 DBG_VALUE debug-use $al, debug-use $noreg, !16, !DIExpression(), debug-location !19
210 renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags
211 JMP_1 %bb.1
212 ...