summaryrefslogtreecommitdiffstats
path: root/llvm/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
commitdca8d3b183701351cc2aeda45147f906e8dc89b0 (patch)
tree9f26143ac9d11d29c525cec756ca0414145af3ac /llvm/lib/Transforms
parent7293f0f344283cbd6f0409e5a674bab27e399507 (diff)
downloadbcm5719-llvm-dca8d3b183701351cc2aeda45147f906e8dc89b0.tar.gz
bcm5719-llvm-dca8d3b183701351cc2aeda45147f906e8dc89b0.zip
Do not ignore iv uses outside the loop.
This one slipped through cracks very well. llvm-svn: 56284
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp b/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp
index d8a1eb68aa3..8cafe7424d0 100644
--- a/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/llvm/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) {
OpenPOWER on IntegriCloud