[llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Aug 3 14:40:40 PDT 2006
Changes in directory llvm/lib/Transforms/Utils:
SimplifyCFG.cpp updated: 1.98 -> 1.99
---
Log message:
Fix PR867: http://llvm.org/PR867 (and maybe 868) and testcsae:
Transforms/SimplifyCFG/2006-08-03-Crash.ll
---
Diffs of the changes: (+25 -6)
SimplifyCFG.cpp | 31 +++++++++++++++++++++++++------
1 files changed, 25 insertions(+), 6 deletions(-)
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.98 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.99
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.98 Mon Jun 12 15:18:01 2006
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Thu Aug 3 16:40:24 2006
@@ -459,12 +459,31 @@
/// has no side effects, nuke it. If it uses any instructions that become dead
/// because the instruction is now gone, nuke them too.
static void ErasePossiblyDeadInstructionTree(Instruction *I) {
- if (isInstructionTriviallyDead(I)) {
- std::vector<Value*> Operands(I->op_begin(), I->op_end());
- I->getParent()->getInstList().erase(I);
- for (unsigned i = 0, e = Operands.size(); i != e; ++i)
- if (Instruction *OpI = dyn_cast<Instruction>(Operands[i]))
- ErasePossiblyDeadInstructionTree(OpI);
+ if (!isInstructionTriviallyDead(I)) return;
+
+ std::vector<Instruction*> InstrsToInspect;
+ InstrsToInspect.push_back(I);
+
+ while (!InstrsToInspect.empty()) {
+ I = InstrsToInspect.back();
+ InstrsToInspect.pop_back();
+
+ if (!isInstructionTriviallyDead(I)) continue;
+
+ // If I is in the work list multiple times, remove previous instances.
+ for (unsigned i = 0, e = InstrsToInspect.size(); i != e; ++i)
+ if (InstrsToInspect[i] == I) {
+ InstrsToInspect.erase(InstrsToInspect.begin()+i);
+ --i, --e;
+ }
+
+ // Add operands of dead instruction to worklist.
+ for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
+ if (Instruction *OpI = dyn_cast<Instruction>(I->getOperand(i)))
+ InstrsToInspect.push_back(OpI);
+
+ // Remove dead instruction.
+ I->eraseFromParent();
}
}
More information about the llvm-commits
mailing list