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 | 65a9ca9a76643d2357e25c4b9268a67ec13fd2cd (patch) | |
tree | 069faef77f27721f43d08ae17facfc3aa34df917 /lib/Transforms/Scalar/LoopIndexSplit.cpp | |
parent | 8dba36c3339570667055abe4aab0d0ad89c07e16 (diff) | |
download | external_llvm-65a9ca9a76643d2357e25c4b9268a67ec13fd2cd.tar.gz external_llvm-65a9ca9a76643d2357e25c4b9268a67ec13fd2cd.tar.bz2 external_llvm-65a9ca9a76643d2357e25c4b9268a67ec13fd2cd.zip |
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) { |