diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index 2ba2ea717b2c8..5ed67bd0a121e 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -1019,13 +1019,11 @@ bool TailDuplicator::tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB, DenseMap LocalVRMap; SmallVector, 4> CopyInfos; - MachineBasicBlock::iterator I = TailBB->begin(); // Process PHI instructions first. - while (I != TailBB->end() && I->isPHI()) { + for (MachineInstr &MI : make_early_inc_range(TailBB->phis())) { // Replace the uses of the def of the PHI with the register coming // from PredBB. - MachineInstr *MI = &*I++; - processPHI(MI, TailBB, PredBB, LocalVRMap, CopyInfos, UsedByPhi, false); + processPHI(&MI, TailBB, PredBB, LocalVRMap, CopyInfos, UsedByPhi, false); } appendCopies(PredBB, CopyInfos, Copies); } diff --git a/llvm/lib/CodeGen/UnreachableBlockElim.cpp b/llvm/lib/CodeGen/UnreachableBlockElim.cpp index 5e8514f525e9d..549d902f3b799 100644 --- a/llvm/lib/CodeGen/UnreachableBlockElim.cpp +++ b/llvm/lib/CodeGen/UnreachableBlockElim.cpp @@ -152,18 +152,18 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) { // Prune unneeded PHI entries. SmallPtrSet preds(BB.pred_begin(), BB.pred_end()); - MachineBasicBlock::iterator phi = BB.begin(); - while (phi != BB.end() && phi->isPHI()) { - for (unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2) - if (!preds.count(phi->getOperand(i).getMBB())) { - phi->removeOperand(i); - phi->removeOperand(i-1); + for (MachineInstr &Phi : make_early_inc_range(BB.phis())) { + for (unsigned i = Phi.getNumOperands() - 1; i >= 2; i -= 2) { + if (!preds.count(Phi.getOperand(i).getMBB())) { + Phi.removeOperand(i); + Phi.removeOperand(i - 1); ModifiedPHI = true; } + } - if (phi->getNumOperands() == 3) { - const MachineOperand &Input = phi->getOperand(1); - const MachineOperand &Output = phi->getOperand(0); + if (Phi.getNumOperands() == 3) { + const MachineOperand &Input = Phi.getOperand(1); + const MachineOperand &Output = Phi.getOperand(0); Register InputReg = Input.getReg(); Register OutputReg = Output.getReg(); assert(Output.getSubReg() == 0 && "Cannot have output subregister"); @@ -182,16 +182,13 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) { // insert a COPY instead of simply replacing the output // with the input. const TargetInstrInfo *TII = F.getSubtarget().getInstrInfo(); - BuildMI(BB, BB.getFirstNonPHI(), phi->getDebugLoc(), + BuildMI(BB, BB.getFirstNonPHI(), Phi.getDebugLoc(), TII->get(TargetOpcode::COPY), OutputReg) .addReg(InputReg, getRegState(Input), InputSub); } - phi++->eraseFromParent(); + Phi.eraseFromParent(); } - continue; } - - ++phi; } }