aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-08-08 18:33:12 +0000
committerDan Gohman <gohman@apple.com>2008-08-08 18:33:12 +0000
commitd9cc749318cc9ab4f36efe8a44201a72adbda2b2 (patch)
tree67008cfe273e0966635c327a2b87aa7461767609 /lib/Analysis/ScalarEvolution.cpp
parentd9ced092998b5ea3b10ab32b8f2407022b4508db (diff)
Canonicalize nested AddRecs in by nesting them in order of loop depth.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54545 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 84e02e47a0..00a4475e28 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -1158,6 +1158,19 @@ SCEVHandle ScalarEvolution::getAddRecExpr(std::vector<SCEVHandle> &Operands,
return getAddRecExpr(Operands, L); // { X,+,0 } --> X
}
+ // Canonicalize nested AddRecs in by nesting them in order of loop depth.
+ if (SCEVAddRecExpr *NestedAR = dyn_cast<SCEVAddRecExpr>(Operands[0])) {
+ const Loop* NestedLoop = NestedAR->getLoop();
+ if (L->getLoopDepth() < NestedLoop->getLoopDepth()) {
+ std::vector<SCEVHandle> NestedOperands(NestedAR->op_begin(),
+ NestedAR->op_end());
+ SCEVHandle NestedARHandle(NestedAR);
+ Operands[0] = NestedAR->getStart();
+ NestedOperands[0] = getAddRecExpr(Operands, L);
+ return getAddRecExpr(NestedOperands, NestedLoop);
+ }
+ }
+
SCEVAddRecExpr *&Result =
(*SCEVAddRecExprs)[std::make_pair(L, std::vector<SCEV*>(Operands.begin(),
Operands.end()))];