diff options
author | Dan Gohman <gohman@apple.com> | 2009-05-02 18:29:22 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-05-02 18:29:22 +0000 |
commit | afc36a9520971832dfbebc0333593bf5d3098296 (patch) | |
tree | 9f9a8cd11e9dfce8900d1a030300eed0ffca00a0 /lib/Transforms/Scalar | |
parent | fb7d35f22a958747dd3ae8861ae3ce018146131c (diff) | |
download | external_llvm-afc36a9520971832dfbebc0333593bf5d3098296.zip external_llvm-afc36a9520971832dfbebc0333593bf5d3098296.tar.gz external_llvm-afc36a9520971832dfbebc0333593bf5d3098296.tar.bz2 |
Previously, RecursivelyDeleteDeadInstructions provided an option
of returning a list of pointers to Values that are deleted. This was
unsafe, because the pointers in the list are, by nature of what
RecursivelyDeleteDeadInstructions does, always dangling. Replace this
with a simple callback mechanism. This may eventually be removed if
all clients can reasonably be expected to use CallbackVH.
Use this to factor out the dead-phi-cycle-elimination code from LSR
utility function, and generalize it to use the
RecursivelyDeleteTriviallyDeadInstructions utility function.
This makes LSR more aggressive about eliminating dead PHI cycles;
adjust tests to either be less trivial or to simply expect fewer
instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70636 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r-- | lib/Transforms/Scalar/LoopStrengthReduce.cpp | 51 |
1 files changed, 15 insertions, 36 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index e550200..b940665 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -32,6 +32,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/ValueHandle.h" #include "llvm/Target/TargetLowering.h" #include <algorithm> using namespace llvm; @@ -2138,6 +2139,7 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond, CondUse = &IVUsesByStride[*NewStride].Users.back(); CondStride = NewStride; ++NumEliminated; + Changed = true; } return Cond; @@ -2501,44 +2503,21 @@ bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager &LPM) { StrideOrder.clear(); // Clean up after ourselves - if (!DeadInsts.empty()) { + if (!DeadInsts.empty()) DeleteTriviallyDeadInstructions(); - 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 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 - // where each node in the cycle has degree one, i.e. only one use, - // and is an instruction with no side effects. - // - // FIXME: this needs to eliminate an induction variable even if it's being - // compared against some value to decide loop termination. - if (!PN->hasOneUse()) - continue; - - SmallPtrSet<PHINode *, 4> PHIs; - for (Instruction *J = dyn_cast<Instruction>(*PN->use_begin()); - J && J->hasOneUse() && !J->mayWriteToMemory(); - J = dyn_cast<Instruction>(*J->use_begin())) { - // If we find the original PHI, we've discovered a cycle. - if (J == PN) { - // Break the cycle and mark the PHI for deletion. - SE->deleteValueFromRecords(PN); - PN->replaceAllUsesWith(UndefValue::get(PN->getType())); - DeadInsts.push_back(PN); - Changed = true; - break; - } - // If we find a PHI more than once, we're on a cycle that - // won't prove fruitful. - if (isa<PHINode>(J) && !PHIs.insert(cast<PHINode>(J))) - break; - } + // At this point, it is worth checking to see if any recurrence PHIs are also + // dead, so that we can remove them as well. To keep ScalarEvolution + // current, use a ValueDeletionListener class. + struct LSRListener : public ValueDeletionListener { + ScalarEvolution &SE; + explicit LSRListener(ScalarEvolution &se) : SE(se) {} + + virtual void ValueWillBeDeleted(Value *V) { + SE.deleteValueFromRecords(V); } - DeleteTriviallyDeadInstructions(); - } + } VDL(*SE); + DeleteDeadPHIs(L->getHeader(), &VDL); + return Changed; } |