[llvm-commits] [llvm] r72152 - /llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Dan Gohman gohman at apple.com
Tue May 19 18:01:26 PDT 2009


Author: djg
Date: Tue May 19 20:01:24 2009
New Revision: 72152

URL: http://llvm.org/viewvc/llvm-project?rev=72152&view=rev
Log:
Teach SCEV::isLoopInvariant and SCEV::hasComputableLoopEvolution
about the convention from LoopInfo that a null Loop* means the entire
function body.

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=72152&r1=72151&r2=72152&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Tue May 19 20:01:24 2009
@@ -388,7 +388,9 @@
 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 @@
 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;
 }
 





More information about the llvm-commits mailing list