@@ -152,18 +152,18 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
152
152
// Prune unneeded PHI entries.
153
153
SmallPtrSet<MachineBasicBlock*, 8 > preds (BB.pred_begin (),
154
154
BB.pred_end ());
155
- MachineBasicBlock::iterator phi = BB.begin ();
156
- while (phi != BB.end () && phi->isPHI ()) {
157
- for (unsigned i = phi->getNumOperands () - 1 ; i >= 2 ; i-=2 )
158
- if (!preds.count (phi->getOperand (i).getMBB ())) {
159
- phi->removeOperand (i);
160
- phi->removeOperand (i-1 );
155
+ for (MachineInstr &Phi : make_early_inc_range (BB.phis ())) {
156
+ for (unsigned i = Phi.getNumOperands () - 1 ; i >= 2 ; i -= 2 ) {
157
+ if (!preds.count (Phi.getOperand (i).getMBB ())) {
158
+ Phi.removeOperand (i);
159
+ Phi.removeOperand (i - 1 );
161
160
ModifiedPHI = true ;
162
161
}
162
+ }
163
163
164
- if (phi-> getNumOperands () == 3 ) {
165
- const MachineOperand &Input = phi-> getOperand (1 );
166
- const MachineOperand &Output = phi-> getOperand (0 );
164
+ if (Phi. getNumOperands () == 3 ) {
165
+ const MachineOperand &Input = Phi. getOperand (1 );
166
+ const MachineOperand &Output = Phi. getOperand (0 );
167
167
Register InputReg = Input.getReg ();
168
168
Register OutputReg = Output.getReg ();
169
169
assert (Output.getSubReg () == 0 && " Cannot have output subregister" );
@@ -182,16 +182,13 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
182
182
// insert a COPY instead of simply replacing the output
183
183
// with the input.
184
184
const TargetInstrInfo *TII = F.getSubtarget ().getInstrInfo ();
185
- BuildMI (BB, BB.getFirstNonPHI (), phi-> getDebugLoc (),
185
+ BuildMI (BB, BB.getFirstNonPHI (), Phi. getDebugLoc (),
186
186
TII->get (TargetOpcode::COPY), OutputReg)
187
187
.addReg (InputReg, getRegState (Input), InputSub);
188
188
}
189
- phi++-> eraseFromParent ();
189
+ Phi. eraseFromParent ();
190
190
}
191
- continue ;
192
191
}
193
-
194
- ++phi;
195
192
}
196
193
}
197
194
0 commit comments