aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-06-27 05:16:57 +0000
committerDan Gohman <gohman@apple.com>2009-06-27 05:16:57 +0000
commit402142e821f2d19e0436dd37adb5890a9c134dea (patch)
tree8884c3e980dc1c704244ba6a027d5ad4f080cd57 /lib/Transforms
parent09a79a6b1b49ffad54acc8e112cabd7ccbf0d286 (diff)
downloadexternal_llvm-402142e821f2d19e0436dd37adb5890a9c134dea.zip
external_llvm-402142e821f2d19e0436dd37adb5890a9c134dea.tar.gz
external_llvm-402142e821f2d19e0436dd37adb5890a9c134dea.tar.bz2
When a value is used multiple times within a single PHI, instructions
inserted to replace that value must dominate all of of the basic blocks associated with the uses of the value in the PHI, not just one of them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74376 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index d2ba256..27e377f 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -70,6 +70,7 @@ namespace {
IVUsers *IU;
LoopInfo *LI;
ScalarEvolution *SE;
+ DominatorTree *DT;
bool Changed;
public:
@@ -329,6 +330,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
IU = &getAnalysis<IVUsers>();
LI = &getAnalysis<LoopInfo>();
SE = &getAnalysis<ScalarEvolution>();
+ DT = &getAnalysis<DominatorTree>();
Changed = false;
// If there are any floating-point recurrences, attempt to
@@ -479,12 +481,22 @@ void IndVarSimplify::RewriteIVExpressions(Loop *L, const Type *LargestType,
if (!AR->isLoopInvariant(L) && !Stride->isLoopInvariant(L))
continue;
+ // Determine the insertion point for this user. By default, insert
+ // immediately before the user. The SCEVExpander class will automatically
+ // hoist loop invariants out of the loop. For PHI nodes, there may be
+ // multiple uses, so compute the nearest common dominator for the
+ // incoming blocks.
Instruction *InsertPt = User;
if (PHINode *PHI = dyn_cast<PHINode>(InsertPt))
- for (unsigned i = 0; ; ++i)
+ for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i)
if (PHI->getIncomingValue(i) == Op) {
- InsertPt = PHI->getIncomingBlock(i)->getTerminator();
- break;
+ if (InsertPt == User)
+ InsertPt = PHI->getIncomingBlock(i)->getTerminator();
+ else
+ InsertPt =
+ DT->findNearestCommonDominator(InsertPt->getParent(),
+ PHI->getIncomingBlock(i))
+ ->getTerminator();
}
// Now expand it into actual Instructions and patch it into place.