Fix SCEVAddRecExpr::isLoopInvariant to test if all of its operands

are loop invariant, not just the start operand.

llvm-svn: 74338
This commit is contained in:
Dan Gohman 2009-06-26 22:17:21 +00:00
parent b5c2639f83
commit 06a4e273be
1 changed files with 15 additions and 5 deletions

View File

@ -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;
}