diff options
| author | Bill Wendling <isanbard@gmail.com> | 2011-09-04 09:43:36 +0000 |
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2011-09-04 09:43:36 +0000 |
| commit | 321fb377738b8ff5bc240ead2a6477632b614697 (patch) | |
| tree | ae8d443f0b59f93cc494bd00ee7014e931d793f5 /llvm/lib/Transforms | |
| parent | acaad83cd04870a15fbb666e3992f2d5c45e2d0b (diff) | |
| download | bcm5719-llvm-321fb377738b8ff5bc240ead2a6477632b614697.tar.gz bcm5719-llvm-321fb377738b8ff5bc240ead2a6477632b614697.zip | |
Use Duncan's patch to delete the instructions in reverse order (minus the landingpad and terminator).
llvm-svn: 139090
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 16 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/SCCP.cpp | 16 |
2 files changed, 20 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 51fe2e5a411..f64990fe0b4 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1574,15 +1574,19 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { if (Visited.count(BB)) continue; - // Delete the instructions. - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { - Instruction *Inst = &*I++; - if (isa<TerminatorInst>(Inst)) - break; + // Delete the instructions backwards, as it has a reduced likelihood of + // having to update as many def-use and use-def chains. + Instruction *EndInst = BB->getTerminator(); // Last not to be deleted. + while (EndInst != BB->begin()) { + // Delete the next to last instruction. + BasicBlock::iterator I = EndInst; + Instruction *Inst = --I; if (!Inst->use_empty()) Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); - if (isa<LandingPadInst>(Inst)) + if (isa<LandingPadInst>(Inst)) { + EndInst = Inst; continue; + } if (!isa<DbgInfoIntrinsic>(Inst)) { ++NumDeadInst; MadeIRChange = true; diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 0091a3df7d7..02e6b72d3af 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -1686,15 +1686,19 @@ static void DeleteInstructionInBlock(BasicBlock *BB) { if (isa<TerminatorInst>(BB->begin())) return; - // Delete the instructions. - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { - Instruction *Inst = &*I++; - if (isa<TerminatorInst>(Inst)) - break; + // Delete the instructions backwards, as it has a reduced likelihood of having + // to update as many def-use and use-def chains. + Instruction *EndInst = BB->getTerminator(); // Last not to be deleted. + while (EndInst != BB->begin()) { + // Delete the next to last instruction. + BasicBlock::iterator I = EndInst; + Instruction *Inst = --I; if (!Inst->use_empty()) Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); - if (isa<LandingPadInst>(Inst)) + if (isa<LandingPadInst>(Inst)) { + EndInst = Inst; continue; + } BB->getInstList().erase(Inst); ++NumInstRemoved; } |

