Teach SCEV::isLoopInvariant and SCEV::hasComputableLoopEvolution
authorDan Gohman <gohman@apple.com>
Wed, 20 May 2009 01:01:24 +0000 (01:01 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 20 May 2009 01:01:24 +0000 (01:01 +0000)
about the convention from LoopInfo that a null Loop* means the entire
function body.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72152 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp

index 50ba7ecd5403a20d66b96d2942fc30e1cf519803..85586a20ebf8b1cf61fcc371e06f426885cbb4e5 100644 (file)
@@ -388,7 +388,9 @@ replaceSymbolicValuesWithConcrete(const SCEVHandle &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.
-  return !QueryLoop->contains(L->getHeader()) &&
+  // Add recurrences are never invariant in the function-body (null loop).
+  return QueryLoop &&
+         !QueryLoop->contains(L->getHeader()) &&
          getOperand(0)->isLoopInvariant(QueryLoop);
 }
 
@@ -410,8 +412,10 @@ SCEVUnknown::~SCEVUnknown() { SCEVUnknowns->erase(V); }
 bool SCEVUnknown::isLoopInvariant(const Loop *L) const {
   // All non-instruction values are loop invariant.  All instructions are loop
   // invariant if they are not contained in the specified loop.
+  // Instructions are never considered invariant in the function body
+  // (null loop) because they are defined within the "loop".
   if (Instruction *I = dyn_cast<Instruction>(V))
-    return !L->contains(I->getParent());
+    return L && !L->contains(I->getParent());
   return true;
 }