summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2008-09-17 17:53:47 +0000
committerDevang Patel <dpatel@apple.com>2008-09-17 17:53:47 +0000
commit00622952ce10e762a48f281f970cbfe73cf55ea8 (patch)
tree069faef77f27721f43d08ae17facfc3aa34df917 /lib/Transforms
parent442b1aa94b4544555aceb9a5d5f2a72f2a9132c6 (diff)
downloadllvm-00622952ce10e762a48f281f970cbfe73cf55ea8.tar.gz
llvm-00622952ce10e762a48f281f970cbfe73cf55ea8.tar.bz2
llvm-00622952ce10e762a48f281f970cbfe73cf55ea8.tar.xz
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')
-rw-r--r--lib/Transforms/Scalar/LoopIndexSplit.cpp22
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) {