aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-27 23:23:35 +0000
committerChris Lattner <sabre@nondot.org>2008-11-27 23:23:35 +0000
commit1363949380374636974558813a19e79d01e63b7c (patch)
tree55898ecb109baac9fd655d59d2f2a6bf23d3a658 /lib/Transforms
parent564c0a233010cb1ff2f9ee2d4d16870284d72487 (diff)
Simplify LoopStrengthReduce::DeleteTriviallyDeadInstructions by
making it use RecursivelyDeleteTriviallyDeadInstructions to do the heavy lifting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60195 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index c2f3209f05..5fad309b0d 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -240,31 +240,30 @@ Value *LoopStrengthReduce::getCastedVersionOf(Instruction::CastOps opcode,
/// their operands subsequently dead.
void LoopStrengthReduce::
DeleteTriviallyDeadInstructions(SetVector<Instruction*> &Insts) {
+ SmallVector<Instruction*, 16> DeadInsts;
+
while (!Insts.empty()) {
Instruction *I = Insts.back();
Insts.pop_back();
+
+ // If I is dead, delete it and all the things that it recursively uses
+ // that become dead.
+ RecursivelyDeleteTriviallyDeadInstructions(I, &DeadInsts);
+
+ if (DeadInsts.empty()) continue;
+ Changed = true;
- if (PHINode *PN = dyn_cast<PHINode>(I)) {
- // If all incoming values to the Phi are the same, we can replace the Phi
- // with that value.
- if (Value *PNV = PN->hasConstantValue()) {
- if (Instruction *U = dyn_cast<Instruction>(PNV))
- Insts.insert(U);
- SE->deleteValueFromRecords(PN);
- PN->replaceAllUsesWith(PNV);
- PN->eraseFromParent();
- Changed = true;
- continue;
- }
- }
-
- if (isInstructionTriviallyDead(I)) {
- for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i)
- if (Instruction *U = dyn_cast<Instruction>(*i))
- Insts.insert(U);
- SE->deleteValueFromRecords(I);
- I->eraseFromParent();
- Changed = true;
+ while (!DeadInsts.empty()) {
+ Instruction *DeadInst = DeadInsts.back();
+ DeadInsts.pop_back();
+
+ // Make sure ScalarEvolutions knows this instruction is gone.
+ SE->deleteValueFromRecords(DeadInst);
+
+ // Make sure that this instruction is removed from DeadInsts if it was
+ // recursively removed.
+ if (DeadInst != I)
+ Insts.remove(DeadInst);
}
}
}