summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-06-26 22:36:20 +0000
committerDan Gohman <gohman@apple.com>2009-06-26 22:36:20 +0000
commitcc030b7e514d2596e296c58095efd4cce9a76631 (patch)
treebeb8a7af1bfdd636c8e1362ad6d1d5bf3e75ff37 /llvm/lib/Analysis/ScalarEvolution.cpp
parent2d83134ca603d5e834895232454b56dafbd4131c (diff)
downloadbcm5719-llvm-cc030b7e514d2596e296c58095efd4cce9a76631.tar.gz
bcm5719-llvm-cc030b7e514d2596e296c58095efd4cce9a76631.zip
Fix ScalarEvolution::getAddRecExpr's code which canonicalized the
nesting order of nested AddRec expressions to skip the transformation if it would introduce an AddRec with operands not loop-invariant with respect to its loop. llvm-svn: 74343
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 2d8bd7d53a6..dcb179afd23 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -1651,8 +1651,29 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV*> &Operands,
SmallVector<const SCEV*, 4> NestedOperands(NestedAR->op_begin(),
NestedAR->op_end());
Operands[0] = NestedAR->getStart();
- NestedOperands[0] = getAddRecExpr(Operands, L);
- return getAddRecExpr(NestedOperands, NestedLoop);
+ // AddRecs require their operands be loop-invariant with respect to their
+ // loops. Don't perform this transformation if it would break this
+ // requirement.
+ bool AllInvariant = true;
+ for (unsigned i = 0, e = Operands.size(); i != e; ++i)
+ if (!Operands[i]->isLoopInvariant(L)) {
+ AllInvariant = false;
+ break;
+ }
+ if (AllInvariant) {
+ NestedOperands[0] = getAddRecExpr(Operands, L);
+ AllInvariant = true;
+ for (unsigned i = 0, e = NestedOperands.size(); i != e; ++i)
+ if (!NestedOperands[i]->isLoopInvariant(NestedLoop)) {
+ AllInvariant = false;
+ break;
+ }
+ if (AllInvariant)
+ // Ok, both add recurrences are valid after the transformation.
+ return getAddRecExpr(NestedOperands, NestedLoop);
+ }
+ // Reset Operands to its original state.
+ Operands[0] = NestedAR;
}
}
OpenPOWER on IntegriCloud