diff options
author | Devang Patel <dpatel@apple.com> | 2008-09-17 17:53:47 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2008-09-17 17:53:47 +0000 |
commit | 00622952ce10e762a48f281f970cbfe73cf55ea8 (patch) | |
tree | 069faef77f27721f43d08ae17facfc3aa34df917 /lib/Transforms/Scalar/LoopIndexSplit.cpp | |
parent | 442b1aa94b4544555aceb9a5d5f2a72f2a9132c6 (diff) |
Do not ignore iv uses outside the loop.
This one slipped through cracks very well.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56284 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopIndexSplit.cpp')
-rw-r--r-- | lib/Transforms/Scalar/LoopIndexSplit.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index d8a1eb68aa..8cafe7424d 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -111,6 +111,10 @@ namespace { /// instruction then loop body is executed only for one iteration. In /// such case eliminate loop structure surrounding this loop body. For bool processOneIterationLoop(SplitInfo &SD); + + /// isOneIterationLoop - Return true if split condition is EQ and + /// the IV is not used outside the loop. + bool isOneIterationLoop(ICmpInst *CI); void updateLoopBounds(ICmpInst *CI); /// updateLoopIterationSpace - Current loop body is covered by an AND @@ -248,7 +252,7 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { SI = SplitData.erase(Delete_SI); } } - else if (CI && CI->getPredicate() == ICmpInst::ICMP_EQ) { + else if (isOneIterationLoop(CI)) { Changed = processOneIterationLoop(SD); if (Changed) { ++NumIndexSplit; @@ -276,6 +280,22 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { return Changed; } +/// isOneIterationLoop - Return true if split condition is EQ and +/// the IV is not used outside the loop. +bool LoopIndexSplit::isOneIterationLoop(ICmpInst *CI) { + if (!CI) + return false; + if (CI->getPredicate() != ICmpInst::ICMP_EQ) + return false; + + Value *Incr = IndVar->getIncomingValueForBlock(L->getLoopLatch()); + for (Value::use_iterator UI = Incr->use_begin(), E = Incr->use_end(); + UI != E; ++UI) + if (!L->contains(cast<Instruction>(*UI)->getParent())) + return false; + + return true; +} /// Return true if V is a induction variable or induction variable's /// increment for loop L. void LoopIndexSplit::findIndVar(Value *V, Loop *L) { |