summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2008-05-19 22:23:55 +0000
committerDevang Patel <dpatel@apple.com>2008-05-19 22:23:55 +0000
commitee7bf41c06f3d760792487cbceef747a766e775a (patch)
treebbc973c62a0b512511838a727a67685c98242ab5 /llvm/lib/Transforms
parent123438cc052aa616ebd647920c5152d944c22ec3 (diff)
downloadbcm5719-llvm-ee7bf41c06f3d760792487cbceef747a766e775a.tar.gz
bcm5719-llvm-ee7bf41c06f3d760792487cbceef747a766e775a.zip
Do not erase induction variable increment if it is used outside the loop.
llvm-svn: 51280
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp b/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp
index 8b554444c52..5faec97a971 100644
--- a/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -596,11 +596,27 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
if (isa<PHINode>(I) || I == LTerminator)
continue;
- if (I == IndVarIncrement)
- I->replaceAllUsesWith(ExitValue);
- else
+ if (I == IndVarIncrement) {
+ // Replace induction variable increment if it is not used outside
+ // the loop.
+ bool UsedOutsideLoop = false;
+ for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
+ UI != E; ++UI) {
+ if (Instruction *Use = dyn_cast<Instruction>(UI))
+ if (!L->contains(Use->getParent())) {
+ UsedOutsideLoop = true;
+ break;
+ }
+ }
+ if (!UsedOutsideLoop) {
+ I->replaceAllUsesWith(ExitValue);
+ I->eraseFromParent();
+ }
+ }
+ else {
I->replaceAllUsesWith(UndefValue::get(I->getType()));
- I->eraseFromParent();
+ I->eraseFromParent();
+ }
}
LPM->deleteLoopFromQueue(L);
OpenPOWER on IntegriCloud