llvm.org GIT mirror llvm / 67fcf56
If a val# is defined by an implicit_def and it is being removed, all of the copies off the val# were removed. This causes problem later since the scavenger will see uses of registers without defs. The proper solution is to change the copies into implicit_def's instead. TurnCopyIntoImpDef turns a copy into implicit_def and remove the val# defined by it. This causes an scavenger assertion later if the def reaches other blocks. Disable the transformation if the value live interval extends beyond its def block. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73478 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 10 years ago
2 changed file(s) with 371 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
615615 }
616616
617617 MachineBasicBlock::iterator MII = next(MachineBasicBlock::iterator(CopyMI));
618 CopyMI->removeFromParent();
619618 tii_->reMaterialize(*MBB, MII, DstReg, DefMI);
620619 MachineInstr *NewMI = prior(MII);
621620
622621 if (checkForDeadDef) {
623 // PR4090 fix: Trim interval failed because there was no use of the
624 // source interval in this MBB. If the def is in this MBB too then we
625 // should mark it dead:
626 if (DefMI->getParent() == MBB) {
627 DefMI->addRegisterDead(SrcInt.reg, tri_);
628 SrcLR->end = SrcLR->start + 1;
629 }
630
622 // PR4090 fix: Trim interval failed because there was no use of the
623 // source interval in this MBB. If the def is in this MBB too then we
624 // should mark it dead:
625 if (DefMI->getParent() == MBB) {
626 DefMI->addRegisterDead(SrcInt.reg, tri_);
627 SrcLR->end = SrcLR->start + 1;
628 }
631629 }
632630
633631 // CopyMI may have implicit operands, transfer them over to the newly
646644 }
647645
648646 li_->ReplaceMachineInstrInMaps(CopyMI, NewMI);
649 MBB->getParent()->DeleteMachineInstr(CopyMI);
647 CopyMI->eraseFromParent();
650648 ReMatCopies.insert(CopyMI);
651649 ReMatDefs.insert(DefMI);
652650 ++NumReMats;
966964
967965 /// RemoveCopiesFromValNo - The specified value# is defined by an implicit
968966 /// def and it is being removed. Turn all copies from this value# into
969 /// identity copies so they will be removed.
967 /// implicit_defs.
970968 void SimpleRegisterCoalescing::RemoveCopiesFromValNo(LiveInterval &li,
971969 VNInfo *VNI) {
972970 SmallVector ImpDefs;
978976 MachineInstr *MI = &*RI;
979977 ++RI;
980978 if (MO->isDef()) {
981 if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF) {
979 if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF)
982980 ImpDefs.push_back(MI);
983 }
984981 continue;
985982 }
986983 if (JoinedCopies.count(MI))
993990 unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
994991 if (tii_->isMoveInstr(*MI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) &&
995992 SrcReg == li.reg) {
996 // Each use MI may have multiple uses of this register. Change them all.
997 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
998 MachineOperand &MO = MI->getOperand(i);
999 if (MO.isReg() && MO.getReg() == li.reg)
1000 MO.setReg(DstReg);
1001 }
1002 JoinedCopies.insert(MI);
993 // Change it to an implicit_def.
994 MI->setDesc(tii_->get(TargetInstrInfo::IMPLICIT_DEF));
995 for (int i = MI->getNumOperands() - 1, e = 0; i > e; --i)
996 MI->RemoveOperand(i);
997 // It's no longer a copy, update the valno it defines.
998 unsigned DefIdx = li_->getDefIndex(UseIdx);
999 LiveInterval &DstInt = li_->getInterval(DstReg);
1000 LiveInterval::iterator DLR = DstInt.FindLiveRangeContaining(DefIdx);
1001 assert(DLR != DstInt.end() && "Live range not found!");
1002 assert(DLR->valno->copy == MI);
1003 DLR->valno->copy = NULL;
1004 ReMatCopies.insert(MI);
10031005 } else if (UseIdx > LastUseIdx) {
10041006 LastUseIdx = UseIdx;
10051007 LastUse = MO;
26402642 return false;
26412643 LiveInterval &DstInt = li_->getInterval(DstReg);
26422644 const LiveRange *DstLR = DstInt.getLiveRangeContaining(CopyIdx);
2645 // If the valno extends beyond this basic block, then it's not safe to delete
2646 // the val# or else livein information won't be correct.
2647 MachineBasicBlock *EndMBB = li_->getMBBFromIndex(DstLR->end);
2648 if (EndMBB != MBB)
2649 return false;
26432650 DstInt.removeValNo(DstLR->valno);
26442651 CopyMI->setDesc(tii_->get(TargetInstrInfo::IMPLICIT_DEF));
26452652 for (int i = CopyMI->getNumOperands() - 1, e = 0; i > e; --i)
0 ; RUN: llvm-as < %s | llc -mtriple=armv6-apple-darwin
1
2 %struct.term = type { i32, i32, i32 }
3
4 declare fastcc i8* @memory_Malloc(i32) nounwind
5
6 define fastcc %struct.term* @t1() nounwind {
7 entry:
8 br i1 undef, label %bb, label %bb1
9
10 bb: ; preds = %entry
11 ret %struct.term* undef
12
13 bb1: ; preds = %entry
14 %0 = tail call fastcc i8* @memory_Malloc(i32 12) nounwind ; [#uses=0]
15 %1 = tail call fastcc i8* @memory_Malloc(i32 12) nounwind ; [#uses=0]
16 ret %struct.term* undef
17 }
18
19
20 define i32 @t2(i32 %argc, i8** nocapture %argv) nounwind {
21 entry:
22 br label %bb6.i8
23
24 bb6.i8: ; preds = %memory_CalculateRealBlockSize1374.exit.i, %entry
25 br i1 undef, label %memory_CalculateRealBlockSize1374.exit.i, label %bb.i.i9
26
27 bb.i.i9: ; preds = %bb6.i8
28 br label %memory_CalculateRealBlockSize1374.exit.i
29
30 memory_CalculateRealBlockSize1374.exit.i: ; preds = %bb.i.i9, %bb6.i8
31 %0 = phi i32 [ undef, %bb.i.i9 ], [ undef, %bb6.i8 ] ; [#uses=2]
32 store i32 %0, i32* undef, align 4
33 %1 = urem i32 8184, %0 ; [#uses=1]
34 %2 = sub i32 8188, %1 ; [#uses=1]
35 store i32 %2, i32* undef, align 4
36 br i1 undef, label %memory_Init.exit, label %bb6.i8
37
38 memory_Init.exit: ; preds = %memory_CalculateRealBlockSize1374.exit.i
39 br label %bb.i.i
40
41 bb.i.i: ; preds = %bb.i.i, %memory_Init.exit
42 br i1 undef, label %symbol_Init.exit, label %bb.i.i
43
44 symbol_Init.exit: ; preds = %bb.i.i
45 br label %bb.i.i67
46
47 bb.i.i67: ; preds = %bb.i.i67, %symbol_Init.exit
48 br i1 undef, label %symbol_CreatePrecedence3522.exit, label %bb.i.i67
49
50 symbol_CreatePrecedence3522.exit: ; preds = %bb.i.i67
51 br label %bb.i.i8.i
52
53 bb.i.i8.i: ; preds = %bb.i.i8.i, %symbol_CreatePrecedence3522.exit
54 br i1 undef, label %cont_Create.exit9.i, label %bb.i.i8.i
55
56 cont_Create.exit9.i: ; preds = %bb.i.i8.i
57 br label %bb.i.i.i72
58
59 bb.i.i.i72: ; preds = %bb.i.i.i72, %cont_Create.exit9.i
60 br i1 undef, label %cont_Init.exit, label %bb.i.i.i72
61
62 cont_Init.exit: ; preds = %bb.i.i.i72
63 br label %bb.i103
64
65 bb.i103: ; preds = %bb.i103, %cont_Init.exit
66 br i1 undef, label %subs_Init.exit, label %bb.i103
67
68 subs_Init.exit: ; preds = %bb.i103
69 br i1 undef, label %bb1.i.i.i80, label %cc_Init.exit
70
71 bb1.i.i.i80: ; preds = %subs_Init.exit
72 unreachable
73
74 cc_Init.exit: ; preds = %subs_Init.exit
75 br label %bb.i.i375
76
77 bb.i.i375: ; preds = %bb.i.i375, %cc_Init.exit
78 br i1 undef, label %bb.i439, label %bb.i.i375
79
80 bb.i439: ; preds = %bb.i439, %bb.i.i375
81 br i1 undef, label %opts_DeclareSPASSFlagsAsOptions.exit, label %bb.i439
82
83 opts_DeclareSPASSFlagsAsOptions.exit: ; preds = %bb.i439
84 br i1 undef, label %opts_TranslateShortOptDeclarations.exit.i, label %bb.i.i82
85
86 bb.i.i82: ; preds = %opts_DeclareSPASSFlagsAsOptions.exit
87 unreachable
88
89 opts_TranslateShortOptDeclarations.exit.i: ; preds = %opts_DeclareSPASSFlagsAsOptions.exit
90 br i1 undef, label %list_Length.exit.i.thread.i, label %bb.i.i4.i
91
92 list_Length.exit.i.thread.i: ; preds = %opts_TranslateShortOptDeclarations.exit.i
93 br i1 undef, label %bb18.i.i.i, label %bb26.i.i.i
94
95 bb.i.i4.i: ; preds = %opts_TranslateShortOptDeclarations.exit.i
96 unreachable
97
98 bb18.i.i.i: ; preds = %list_Length.exit.i.thread.i
99 unreachable
100
101 bb26.i.i.i: ; preds = %list_Length.exit.i.thread.i
102 br i1 undef, label %bb27.i142, label %opts_GetOptLongOnly.exit.thread97.i
103
104 opts_GetOptLongOnly.exit.thread97.i: ; preds = %bb26.i.i.i
105 br label %bb27.i142
106
107 bb27.i142: ; preds = %opts_GetOptLongOnly.exit.thread97.i, %bb26.i.i.i
108 br label %bb1.i3.i
109
110 bb1.i3.i: ; preds = %bb1.i3.i, %bb27.i142
111 br i1 undef, label %opts_FreeLongOptsArray.exit.i, label %bb1.i3.i
112
113 opts_FreeLongOptsArray.exit.i: ; preds = %bb1.i3.i
114 br label %bb.i443
115
116 bb.i443: ; preds = %bb.i443, %opts_FreeLongOptsArray.exit.i
117 br i1 undef, label %flag_InitStoreByDefaults3542.exit, label %bb.i443
118
119 flag_InitStoreByDefaults3542.exit: ; preds = %bb.i443
120 br i1 undef, label %bb6.i449, label %bb.i503
121
122 bb6.i449: ; preds = %flag_InitStoreByDefaults3542.exit
123 unreachable
124
125 bb.i503: ; preds = %bb.i503, %flag_InitStoreByDefaults3542.exit
126 br i1 undef, label %flag_CleanStore3464.exit, label %bb.i503
127
128 flag_CleanStore3464.exit: ; preds = %bb.i503
129 br i1 undef, label %bb1.i81.i.preheader, label %bb.i173
130
131 bb.i173: ; preds = %flag_CleanStore3464.exit
132 unreachable
133
134 bb1.i81.i.preheader: ; preds = %flag_CleanStore3464.exit
135 br i1 undef, label %bb1.i64.i.preheader, label %bb5.i179
136
137 bb5.i179: ; preds = %bb1.i81.i.preheader
138 unreachable
139
140 bb1.i64.i.preheader: ; preds = %bb1.i81.i.preheader
141 br i1 undef, label %dfg_DeleteProofList.exit.i, label %bb.i9.i
142
143 bb.i9.i: ; preds = %bb1.i64.i.preheader
144 unreachable
145
146 dfg_DeleteProofList.exit.i: ; preds = %bb1.i64.i.preheader
147 br i1 undef, label %term_DeleteTermList621.exit.i, label %bb.i.i62.i
148
149 bb.i.i62.i: ; preds = %bb.i.i62.i, %dfg_DeleteProofList.exit.i
150 br i1 undef, label %term_DeleteTermList621.exit.i, label %bb.i.i62.i
151
152 term_DeleteTermList621.exit.i: ; preds = %bb.i.i62.i, %dfg_DeleteProofList.exit.i
153 br i1 undef, label %dfg_DFGParser.exit, label %bb.i.i211
154
155 bb.i.i211: ; preds = %term_DeleteTermList621.exit.i
156 unreachable
157
158 dfg_DFGParser.exit: ; preds = %term_DeleteTermList621.exit.i
159 br label %bb.i513
160
161 bb.i513: ; preds = %bb2.i516, %dfg_DFGParser.exit
162 br i1 undef, label %bb2.i516, label %bb1.i514
163
164 bb1.i514: ; preds = %bb.i513
165 unreachable
166
167 bb2.i516: ; preds = %bb.i513
168 br i1 undef, label %bb.i509, label %bb.i513
169
170 bb.i509: ; preds = %bb.i509, %bb2.i516
171 br i1 undef, label %symbol_TransferPrecedence3468.exit511, label %bb.i509
172
173 symbol_TransferPrecedence3468.exit511: ; preds = %bb.i509
174 br i1 undef, label %bb20, label %bb21
175
176 bb20: ; preds = %symbol_TransferPrecedence3468.exit511
177 unreachable
178
179 bb21: ; preds = %symbol_TransferPrecedence3468.exit511
180 br i1 undef, label %cnf_Init.exit, label %bb.i498
181
182 bb.i498: ; preds = %bb21
183 unreachable
184
185 cnf_Init.exit: ; preds = %bb21
186 br i1 undef, label %bb23, label %bb22
187
188 bb22: ; preds = %cnf_Init.exit
189 br i1 undef, label %bb2.i.i496, label %bb.i.i494
190
191 bb.i.i494: ; preds = %bb22
192 unreachable
193
194 bb2.i.i496: ; preds = %bb22
195 unreachable
196
197 bb23: ; preds = %cnf_Init.exit
198 br i1 undef, label %bb28, label %bb24
199
200 bb24: ; preds = %bb23
201 unreachable
202
203 bb28: ; preds = %bb23
204 br i1 undef, label %bb31, label %bb29
205
206 bb29: ; preds = %bb28
207 unreachable
208
209 bb31: ; preds = %bb28
210 br i1 undef, label %bb34, label %bb32
211
212 bb32: ; preds = %bb31
213 unreachable
214
215 bb34: ; preds = %bb31
216 br i1 undef, label %bb83, label %bb66
217
218 bb66: ; preds = %bb34
219 unreachable
220
221 bb83: ; preds = %bb34
222 br i1 undef, label %bb2.i1668, label %bb.i1667
223
224 bb.i1667: ; preds = %bb83
225 unreachable
226
227 bb2.i1668: ; preds = %bb83
228 br i1 undef, label %bb5.i205, label %bb3.i204
229
230 bb3.i204: ; preds = %bb2.i1668
231 unreachable
232
233 bb5.i205: ; preds = %bb2.i1668
234 br i1 undef, label %bb.i206.i, label %ana_AnalyzeSortStructure.exit.i
235
236 bb.i206.i: ; preds = %bb5.i205
237 br i1 undef, label %bb1.i207.i, label %ana_AnalyzeSortStructure.exit.i
238
239 bb1.i207.i: ; preds = %bb.i206.i
240 br i1 undef, label %bb25.i1801.thread, label %bb.i1688
241
242 bb.i1688: ; preds = %bb1.i207.i
243 unreachable
244
245 bb25.i1801.thread: ; preds = %bb1.i207.i
246 unreachable
247
248 ana_AnalyzeSortStructure.exit.i: ; preds = %bb.i206.i, %bb5.i205
249 br i1 undef, label %bb7.i207, label %bb.i1806
250
251 bb.i1806: ; preds = %ana_AnalyzeSortStructure.exit.i
252 br i1 undef, label %bb2.i.i.i1811, label %bb.i.i.i1809
253
254 bb.i.i.i1809: ; preds = %bb.i1806
255 unreachable
256
257 bb2.i.i.i1811: ; preds = %bb.i1806
258 unreachable
259
260 bb7.i207: ; preds = %ana_AnalyzeSortStructure.exit.i
261 br i1 undef, label %bb9.i, label %bb8.i
262
263 bb8.i: ; preds = %bb7.i207
264 unreachable
265
266 bb9.i: ; preds = %bb7.i207
267 br i1 undef, label %bb23.i, label %bb26.i
268
269 bb23.i: ; preds = %bb9.i
270 br i1 undef, label %bb25.i, label %bb24.i
271
272 bb24.i: ; preds = %bb23.i
273 br i1 undef, label %sort_SortTheoryIsTrivial.exit.i, label %bb.i2093
274
275 bb.i2093: ; preds = %bb.i2093, %bb24.i
276 br label %bb.i2093
277
278 sort_SortTheoryIsTrivial.exit.i: ; preds = %bb24.i
279 br i1 undef, label %bb3.i2141, label %bb4.i2143
280
281 bb3.i2141: ; preds = %sort_SortTheoryIsTrivial.exit.i
282 unreachable
283
284 bb4.i2143: ; preds = %sort_SortTheoryIsTrivial.exit.i
285 br i1 undef, label %bb8.i2178, label %bb5.i2144
286
287 bb5.i2144: ; preds = %bb4.i2143
288 br i1 undef, label %bb7.i2177, label %bb1.i28.i
289
290 bb1.i28.i: ; preds = %bb5.i2144
291 br i1 undef, label %bb4.i43.i, label %bb2.i.i2153
292
293 bb2.i.i2153: ; preds = %bb1.i28.i
294 br i1 undef, label %bb4.i.i33.i, label %bb.i.i30.i
295
296 bb.i.i30.i: ; preds = %bb2.i.i2153
297 unreachable
298
299 bb4.i.i33.i: ; preds = %bb2.i.i2153
300 br i1 undef, label %bb9.i.i36.i, label %bb5.i.i34.i
301
302 bb5.i.i34.i: ; preds = %bb4.i.i33.i
303 unreachable
304
305 bb9.i.i36.i: ; preds = %bb4.i.i33.i
306 br i1 undef, label %bb14.i.i.i2163, label %bb10.i.i37.i
307
308 bb10.i.i37.i: ; preds = %bb9.i.i36.i
309 unreachable
310
311 bb14.i.i.i2163: ; preds = %bb9.i.i36.i
312 br i1 undef, label %sort_LinkPrint.exit.i.i, label %bb15.i.i.i2164
313
314 bb15.i.i.i2164: ; preds = %bb14.i.i.i2163
315 unreachable
316
317 sort_LinkPrint.exit.i.i: ; preds = %bb14.i.i.i2163
318 unreachable
319
320 bb4.i43.i: ; preds = %bb1.i28.i
321 unreachable
322
323 bb7.i2177: ; preds = %bb5.i2144
324 unreachable
325
326 bb8.i2178: ; preds = %bb4.i2143
327 br i1 undef, label %sort_ApproxStaticSortTheory.exit, label %bb.i5.i2185.preheader
328
329 bb.i5.i2185.preheader: ; preds = %bb8.i2178
330 br label %bb.i5.i2185
331
332 bb.i5.i2185: ; preds = %bb.i5.i2185, %bb.i5.i2185.preheader
333 br i1 undef, label %sort_ApproxStaticSortTheory.exit, label %bb.i5.i2185
334
335 sort_ApproxStaticSortTheory.exit: ; preds = %bb.i5.i2185, %bb8.i2178
336 br label %bb25.i
337
338 bb25.i: ; preds = %sort_ApproxStaticSortTheory.exit, %bb23.i
339 unreachable
340
341 bb26.i: ; preds = %bb9.i
342 unreachable
343 }