diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 5e06820803c..208375b4823 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1573,41 +1573,20 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { // the instcombine code from having to deal with some bad special cases. for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) if (!Visited.count(BB)) { - Instruction *Term = BB->getTerminator(); - - if (isa(BB->begin())) - continue; - // Delete the instructions backwards, as it has a reduced likelihood of // having to update as many def-use and use-def chains. - std::vector WorkList; - WorkList.reserve(BB->size()); - BasicBlock::iterator I = Term; --I; - - while (true) { - if (!I->getType()->isVoidTy()) - I->replaceAllUsesWith(UndefValue::get(I->getType())); - WorkList.push_back(I); - if (I == BB->begin()) + for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { + Instruction *Inst = &*I++; + if (isa(Inst)) break; - --I; - } - - for (std::vector::iterator - II = WorkList.begin(), IE = WorkList.end(); II != IE; ++II) { - Instruction *Inst = *II; - // Don't remove the landing pad. It should be removed only when its - // invokes are removed. + if (!Inst->use_empty()) + Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); if (isa(Inst)) continue; - - // A debug intrinsic shouldn't force another iteration if we weren't - // going to do one without it. if (!isa(Inst)) { ++NumDeadInst; MadeIRChange = true; } - Inst->eraseFromParent(); } } diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 3d52afa2e10..4ac5b2f9103 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1688,24 +1688,15 @@ static void DeleteInstructionInBlock(BasicBlock *BB) { // Delete the instructions backwards, as it has a reduced likelihood of // having to update as many def-use and use-def chains. - std::vector WorkList; - WorkList.reserve(BB->size()); - BasicBlock::iterator I = --BasicBlock::iterator(BB->getTerminator()); - - while (true) { - if (!I->use_empty()) - I->replaceAllUsesWith(UndefValue::get(I->getType())); - WorkList.push_back(I); - if (I == BB->begin()) + for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { + Instruction *Inst = &*I++; + if (isa(Inst)) break; - --I; - } - - for (std::vector::iterator - II = WorkList.begin(), IE = WorkList.end(); II != IE; ++II) { - if (isa(*II)) + if (!Inst->use_empty()) + Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); + if (isa(Inst)) continue; - BB->getInstList().erase(*II); + BB->getInstList().erase(Inst); ++NumInstRemoved; } }