diff options
author | Dan Gohman <gohman@apple.com> | 2009-06-26 22:17:21 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-06-26 22:17:21 +0000 |
commit | e890eead222abf84fc171b28891a68b65e9addf5 (patch) | |
tree | 361c1acc59935d0522906df3b08e07ada1727c85 /lib/Analysis/ScalarEvolution.cpp | |
parent | 93677c99a4a5a03eae34b8b15d4be70b12a8332c (diff) |
Fix SCEVAddRecExpr::isLoopInvariant to test if all of its operands
are loop invariant, not just the start operand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74338 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | lib/Analysis/ScalarEvolution.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index c98414d66a..2d8bd7d53a 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -327,12 +327,22 @@ SCEVAddRecExpr::replaceSymbolicValuesWithConcrete(const SCEV *Sym, bool SCEVAddRecExpr::isLoopInvariant(const Loop *QueryLoop) const { - // This recurrence is invariant w.r.t to QueryLoop iff QueryLoop doesn't - // contain L and if the start is invariant. // Add recurrences are never invariant in the function-body (null loop). - return QueryLoop && - !QueryLoop->contains(L->getHeader()) && - getOperand(0)->isLoopInvariant(QueryLoop); + if (!QueryLoop) + return false; + + // This recurrence is variant w.r.t. QueryLoop if QueryLoop contains L. + if (QueryLoop->contains(L->getHeader())) + return false; + + // This recurrence is variant w.r.t. QueryLoop if any of its operands + // are variant. + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) + if (!getOperand(i)->isLoopInvariant(QueryLoop)) + return false; + + // Otherwise it's loop-invariant. + return true; } |