@@ -152,18 +152,18 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
152152 // Prune unneeded PHI entries.
153153 SmallPtrSet<MachineBasicBlock*, 8 > preds (BB.pred_begin (),
154154 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 );
161160 ModifiedPHI = true ;
162161 }
162+ }
163163
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 );
167167 Register InputReg = Input.getReg ();
168168 Register OutputReg = Output.getReg ();
169169 assert (Output.getSubReg () == 0 && " Cannot have output subregister" );
@@ -182,16 +182,13 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
182182 // insert a COPY instead of simply replacing the output
183183 // with the input.
184184 const TargetInstrInfo *TII = F.getSubtarget ().getInstrInfo ();
185- BuildMI (BB, BB.getFirstNonPHI (), phi-> getDebugLoc (),
185+ BuildMI (BB, BB.getFirstNonPHI (), Phi. getDebugLoc (),
186186 TII->get (TargetOpcode::COPY), OutputReg)
187187 .addReg (InputReg, getRegState (Input), InputSub);
188188 }
189- phi++-> eraseFromParent ();
189+ Phi. eraseFromParent ();
190190 }
191- continue ;
192191 }
193-
194- ++phi;
195192 }
196193 }
197194
0 commit comments