Factor code for testing whether replacing one value with another

preserves LCSSA form out of ScalarEvolution and into the LoopInfo
class.  Use it to check that SimplifyInstruction simplifications
are not breaking LCSSA form.  Fixes PR8622.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119727 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands
2010-11-18 19:59:41 +00:00
parent 707120047e
commit d0c6f3dafd
5 changed files with 72 additions and 37 deletions
+2 -17
View File
@@ -2768,25 +2768,10 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) {
// PHI's incoming blocks are in a different loop, in which case doing so
// risks breaking LCSSA form. Instcombine would normally zap these, but
// it doesn't have DominatorTree information, so it may miss cases.
if (Value *V = SimplifyInstruction(PN, TD, DT)) {
Instruction *I = dyn_cast<Instruction>(V);
// Only instructions are problematic for preserving LCSSA form.
if (!I)
if (Value *V = SimplifyInstruction(PN, TD, DT))
if (LI->replacementPreservesLCSSAForm(PN, V))
return getSCEV(V);
// If the instruction is not defined in a loop, then it can be used freely.
Loop *ILoop = LI->getLoopFor(I->getParent());
if (!ILoop)
return getSCEV(I);
// If the instruction is defined in the same loop as the phi node, or in a
// loop that contains the phi node loop as an inner loop, then using it as
// a replacement for the phi node will not break LCSSA form.
Loop *PNLoop = LI->getLoopFor(PN->getParent());
if (ILoop->contains(PNLoop))
return getSCEV(I);
}
// If it's not a loop phi, we can't handle it yet.
return getUnknown(PN);
}