diff options
| author | Devang Patel <dpatel@apple.com> | 2008-05-19 22:23:55 +0000 |
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2008-05-19 22:23:55 +0000 |
| commit | ee7bf41c06f3d760792487cbceef747a766e775a (patch) | |
| tree | bbc973c62a0b512511838a727a67685c98242ab5 /llvm/lib/Transforms | |
| parent | 123438cc052aa616ebd647920c5152d944c22ec3 (diff) | |
| download | bcm5719-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.cpp | 24 |
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); |

