llvm.org GIT mirror llvm / 296185c
fix two problems with machine sinking: 1. Sinking would crash when the first instruction of a block was sunk due to iterator problems. 2. Instructions could be sunk to their current block, causing an infinite loop. This fixes PR3968 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68787 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 42 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
110110 }
111111
112112 bool MachineSinking::ProcessBlock(MachineBasicBlock &MBB) {
113 // Can't sink anything out of a block that has less than two successors.
114 if (MBB.succ_size() <= 1 || MBB.empty()) return false;
115
113116 bool MadeChange = false;
114
115 // Can't sink anything out of a block that has less than two successors.
116 if (MBB.succ_size() <= 1) return false;
117
117
118118 // Walk the basic block bottom-up. Remember if we saw a store.
119 bool SawStore = false;
120 for (MachineBasicBlock::iterator I = MBB.end(); I != MBB.begin(); ){
121 MachineBasicBlock::iterator LastIt = I;
122 if (SinkInstruction(--I, SawStore)) {
123 I = LastIt;
124 ++NumSunk;
125 }
126 }
119 MachineBasicBlock::iterator I = MBB.end();
120 --I;
121 bool ProcessedBegin, SawStore = false;
122 do {
123 MachineInstr *MI = I; // The instruction to sink.
124
125 // Predecrement I (if it's not begin) so that it isn't invalidated by
126 // sinking.
127 ProcessedBegin = I == MBB.begin();
128 if (!ProcessedBegin)
129 --I;
130
131 if (SinkInstruction(MI, SawStore))
132 ++NumSunk, MadeChange = true;
133
134 // If we just processed the first instruction in the block, we're done.
135 } while (!ProcessedBegin);
127136
128137 return MadeChange;
129138 }
217226 if (SuccToSinkTo->isLandingPad())
218227 return false;
219228
229 // If is not possible to sink an instruction into its own block. This can
230 // happen with loops.
231 if (MI->getParent() == SuccToSinkTo)
232 return false;
233
220234 DEBUG(cerr << "Sink instr " << *MI);
221235 DEBUG(cerr << "to block " << *SuccToSinkTo);
222236
0 ; RUN: llvm-as < %s | llc
1
2 define void @QRiterate(i32 %p.1, double %tmp.212) nounwind {
3 entry:
4 br i1 false, label %shortcirc_next.1, label %exit.1.critedge
5
6 shortcirc_next.1: ; preds = %shortcirc_next.1, %entry
7 %tmp.213 = fcmp une double %tmp.212, 0.000000e+00 ; [#uses=1]
8 br i1 %tmp.213, label %shortcirc_next.1, label %exit.1
9
10 exit.1.critedge: ; preds = %entry
11 ret void
12
13 exit.1: ; preds = %shortcirc_next.1
14 ret void
15 }