diff options
author | Chris Lattner <sabre@nondot.org> | 2008-12-01 06:11:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-12-01 06:11:32 +0000 |
commit | 2757a1d273fa0556a74a0794f308edeee4bd740e (patch) | |
tree | 4082bef3f816d8ab5604645a93e948fb954e11cd | |
parent | 9db479f59c40147ef19f556b84c5425a0ec40e10 (diff) | |
download | external_llvm-2757a1d273fa0556a74a0794f308edeee4bd740e.zip external_llvm-2757a1d273fa0556a74a0794f308edeee4bd740e.tar.gz external_llvm-2757a1d273fa0556a74a0794f308edeee4bd740e.tar.bz2 |
simplify DeleteTriviallyDeadInstructions again, unlike my previous
buggy rewrite, this notifies ScalarEvolution of a pending instruction
about to be removed and then erases it, instead of erasing it then
notifying.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60329 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/LoopStrengthReduce.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index c2f3209..7d4a1041 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -244,28 +244,21 @@ DeleteTriviallyDeadInstructions(SetVector<Instruction*> &Insts) { Instruction *I = Insts.back(); Insts.pop_back(); - 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)) + continue; + + SE->deleteValueFromRecords(I); - 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)) + for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i) { + if (Instruction *U = dyn_cast<Instruction>(*i)) { + *i = 0; + if (U->use_empty()) Insts.insert(U); - SE->deleteValueFromRecords(I); - I->eraseFromParent(); - Changed = true; + } } + + I->eraseFromParent(); + Changed = true; } } @@ -2067,7 +2060,7 @@ bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager &LPM) { BasicBlock::iterator I = L->getHeader()->begin(); while (PHINode *PN = dyn_cast<PHINode>(I++)) { // At this point, we know that we have killed one or more IV users. - // It is worth checking to see if the cann indvar is also + // It is worth checking to see if the cannonical indvar is also // dead, so that we can remove it as well. // // We can remove a PHI if it is on a cycle in the def-use graph |