An add recurrence is loop-invariant in any loop inside of its
authorDan Gohman <gohman@apple.com>
Fri, 13 Aug 2010 20:11:39 +0000 (20:11 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 13 Aug 2010 20:11:39 +0000 (20:11 +0000)
associated loop. This avoids potentially expensive traversals
of the add recurrence's operands.

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

lib/Analysis/ScalarEvolution.cpp

index 394e0159db8a059a657c1ed3afb5516f838ccee9..dee7a1f8d93e9b382b6102c37494d6a77802e629 100644 (file)
@@ -303,6 +303,10 @@ bool SCEVAddRecExpr::isLoopInvariant(const Loop *QueryLoop) const {
   if (QueryLoop->contains(L))
     return false;
 
+  // This recurrence is invariant w.r.t. QueryLoop if L contains QueryLoop.
+  if (L->contains(QueryLoop))
+    return true;
+
   // This recurrence is variant w.r.t. QueryLoop if any of its operands
   // are variant.
   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)