summaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2011-09-01 01:28:11 +0000
committerBill Wendling <isanbard@gmail.com>2011-09-01 01:28:11 +0000
commita8d1393093d67091d47fa87a4ce86c0adcead6a0 (patch)
tree7efa780abcce26cb80fb1fec8d6829336a814b00 /lib/Transforms/InstCombine
parentc1b4cd6c11f58f3b49d09bf30acc165cb0d9a33b (diff)
downloadllvm-a8d1393093d67091d47fa87a4ce86c0adcead6a0.tar.gz
llvm-a8d1393093d67091d47fa87a4ce86c0adcead6a0.tar.bz2
llvm-a8d1393093d67091d47fa87a4ce86c0adcead6a0.tar.xz
Resubmit with fix. Properly remove the instructions except for landingpad, which should be removed only when its invokes are.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138932 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine')
-rw-r--r--lib/Transforms/InstCombine/InstructionCombining.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp
index 838678b9fa..5e06820803 100644
--- a/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1574,22 +1574,41 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
if (!Visited.count(BB)) {
Instruction *Term = BB->getTerminator();
- while (Term != BB->begin()) { // Remove instrs bottom-up
- BasicBlock::iterator I = Term; --I;
- DEBUG(errs() << "IC: DCE: " << *I << '\n');
+ if (isa<TerminatorInst>(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<Instruction*> 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())
+ break;
+ --I;
+ }
+
+ for (std::vector<Instruction*>::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 (isa<LandingPadInst>(Inst))
+ continue;
+
// A debug intrinsic shouldn't force another iteration if we weren't
// going to do one without it.
- if (!isa<DbgInfoIntrinsic>(I)) {
+ if (!isa<DbgInfoIntrinsic>(Inst)) {
++NumDeadInst;
MadeIRChange = true;
}
- // If I is not void type then replaceAllUsesWith undef.
- // This allows ValueHandlers and custom metadata to adjust itself.
- if (!I->getType()->isVoidTy())
- I->replaceAllUsesWith(UndefValue::get(I->getType()));
- I->eraseFromParent();
+ Inst->eraseFromParent();
}
}
}