Do not erase induction variable increment if it is used outside the loop.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51280 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2008-05-19 22:23:55 +00:00
parent 45b4e48b18
commit 52abbf5d8a
2 changed files with 61 additions and 4 deletions

View File

@@ -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);