diff options
author | Owen Anderson <resistor@mac.com> | 2006-07-14 18:49:15 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2006-07-14 18:49:15 +0000 |
commit | c1be492f94da7e53eef408c346b25c551c6bdf07 (patch) | |
tree | 92a8d8b10c91f493c3660e2ce6a56e29ec308cb0 /lib/Transforms | |
parent | 518f9c7ad0566a69886a4db1b76e995df22bca0f (diff) |
Hopefully the final attempt at making IndVars preserve LCSSA.
This should fix PR 831.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29141 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index a46916077a..e734c06a9f 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -358,8 +358,36 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) { // Rewrite any users of the computed value outside of the loop // with the newly computed value. - for (unsigned i = 0, e = ExtraLoopUsers.size(); i != e; ++i) - ExtraLoopUsers[i]->replaceUsesOfWith(I, NewVal); + for (unsigned i = 0, e = ExtraLoopUsers.size(); i != e; ++i) { + PHINode* PN = dyn_cast<PHINode>(ExtraLoopUsers[i]); + if (PN && PN->getNumOperands() == 2 && + !L->contains(PN->getParent())) { + // We're dealing with an LCSSA Phi. Handle it specially. + Instruction* LCSSAInsertPt = BlockToInsertInto->begin(); + + Instruction* NewInstr = dyn_cast<Instruction>(NewVal); + if (NewInstr && !isa<PHINode>(NewInstr) && + !L->contains(NewInstr->getParent())) + for (unsigned j = 0; j < NewInstr->getNumOperands(); ++j){ + Instruction* PredI = + dyn_cast<Instruction>(NewInstr->getOperand(j)); + if (PredI && L->contains(PredI->getParent())) { + PHINode* NewLCSSA = new PHINode(PredI->getType(), + PredI->getName() + ".lcssa", + LCSSAInsertPt); + NewLCSSA->addIncoming(PredI, + BlockToInsertInto->getSinglePredecessor()); + + NewInstr->replaceUsesOfWith(PredI, NewLCSSA); + } + } + + PN->replaceAllUsesWith(NewVal); + PN->eraseFromParent(); + } else { + ExtraLoopUsers[i]->replaceUsesOfWith(I, NewVal); + } + } // If this instruction is dead now, schedule it to be removed. if (I->use_empty()) |