diff options
author | Dan Gohman <gohman@apple.com> | 2009-06-26 22:36:20 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-06-26 22:36:20 +0000 |
commit | 9a80b459ed5c6c55f4e20e443e86c459e89170c9 (patch) | |
tree | 6b9fbfa131e58a2b3e62a2560047f62e5cb6d259 /lib/Analysis | |
parent | f7f02a9c7f833736aa4a22a6fd3606b9f118ad1f (diff) | |
download | external_llvm-9a80b459ed5c6c55f4e20e443e86c459e89170c9.zip external_llvm-9a80b459ed5c6c55f4e20e443e86c459e89170c9.tar.gz external_llvm-9a80b459ed5c6c55f4e20e443e86c459e89170c9.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74343 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/ScalarEvolution.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 2d8bd7d..dcb179a 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/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; } } |