diff options
author | Duncan Sands <baldrick@free.fr> | 2010-11-17 20:49:12 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2010-11-17 20:49:12 +0000 |
commit | 6f8a5ddcd8d7e5b041ff083009ae84de0e6e588b (patch) | |
tree | 5bc9a4b56f9ba384112ab0b5cae746282ba66aa7 /lib/Analysis/ScalarEvolution.cpp | |
parent | 5aba9f694fbfb78df2aa2a228e85ba4c27f3037b (diff) |
Before replacing a phi node with a different value, it
needs to be checked that this won't break LCSSA form.
Change the existing checking method to a more direct one:
rather than seeing if all predecessors belong to the loop,
check that the replacing value is either not in any loop or
is in a loop that contains the phi node.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119556 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | lib/Analysis/ScalarEvolution.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index deea0004d5..73b03bcfe9 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -2879,18 +2879,22 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { // 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)) { - // TODO: The following check is suboptimal. For example, it is pointless - // if V is a constant. Since the problematic case is if V is defined inside - // a deeper loop, it would be better to check for that directly. - bool AllSameLoop = true; - Loop *PNLoop = LI->getLoopFor(PN->getParent()); - for (size_t i = 0, e = PN->getNumIncomingValues(); i != e; ++i) - if (LI->getLoopFor(PN->getIncomingBlock(i)) != PNLoop) { - AllSameLoop = false; - break; - } - if (AllSameLoop) + Instruction *I = dyn_cast<Instruction>(V); + // Only instructions are problematic for preserving LCSSA form. + if (!I) 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. |