[llvm-commits] [llvm] r119556 - /llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Duncan Sands
baldrick at free.fr
Wed Nov 17 12:49:12 PST 2010
Author: baldrick
Date: Wed Nov 17 14:49:12 2010
New Revision: 119556
URL: http://llvm.org/viewvc/llvm-project?rev=119556&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=119556&r1=119555&r2=119556&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Nov 17 14:49:12 2010
@@ -2879,18 +2879,22 @@
// 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.
More information about the llvm-commits
mailing list