Even if there are not any induction variables in the loop, if we can compute
authorChris Lattner <sabre@nondot.org>
Sat, 17 Apr 2004 18:08:33 +0000 (18:08 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Apr 2004 18:08:33 +0000 (18:08 +0000)
the trip count for the loop, insert one so that we can canonicalize the exit
condition.

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

lib/Transforms/Scalar/IndVarSimplify.cpp

index 9bc897fe022e2484f828f250323d753c6d433249..fa81f81f7435043d09ee438df62f8170c4202099 100644 (file)
@@ -368,7 +368,17 @@ void IndVarSimplify::runOnLoop(Loop *L) {
 
   // If there are no induction variables in the loop, there is nothing more to
   // do.
-  if (IndVars.empty()) return;
+  if (IndVars.empty()) {
+    // Actually, if we know how many times the loop iterates, lets insert a
+    // canonical induction variable to help subsequent passes.
+    if (!isa<SCEVCouldNotCompute>(IterationCount)) {
+      ScalarEvolutionRewriter Rewriter(*SE, *LI);
+      Rewriter.GetOrInsertCanonicalInductionVariable(L,
+                                                     IterationCount->getType());
+      LinearFunctionTestReplace(L, IterationCount, Rewriter);
+    }
+    return;
+  }
 
   // Compute the type of the largest recurrence expression.
   //