[llvm-commits] [llvm] r138967 - in /llvm/trunk/lib/Transforms: InstCombine/InstructionCombining.cpp Scalar/SCCP.cpp
Bill Wendling
isanbard at gmail.com
Thu Sep 1 14:28:33 PDT 2011
Author: void
Date: Thu Sep 1 16:28:33 2011
New Revision: 138967
URL: http://llvm.org/viewvc/llvm-project?rev=138967&view=rev
Log:
Change worklist driven deletion to be an iterative process.
Duncan noticed this!
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=138967&r1=138966&r2=138967&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Thu Sep 1 16:28:33 2011
@@ -1573,41 +1573,20 @@
// 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<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())
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
+ Instruction *Inst = &*I++;
+ if (isa<TerminatorInst>(Inst))
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 (!Inst->use_empty())
+ Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
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>(Inst)) {
++NumDeadInst;
MadeIRChange = true;
}
-
Inst->eraseFromParent();
}
}
Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=138967&r1=138966&r2=138967&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Thu Sep 1 16:28:33 2011
@@ -1688,24 +1688,15 @@
// 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 = --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<TerminatorInst>(Inst))
break;
- --I;
- }
-
- for (std::vector<Instruction*>::iterator
- II = WorkList.begin(), IE = WorkList.end(); II != IE; ++II) {
- if (isa<LandingPadInst>(*II))
+ if (!Inst->use_empty())
+ Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
+ if (isa<LandingPadInst>(Inst))
continue;
- BB->getInstList().erase(*II);
+ BB->getInstList().erase(Inst);
++NumInstRemoved;
}
}
More information about the llvm-commits
mailing list