Canonicalize inner loops before outer loops. Inner loop canonicalization
authorChris Lattner <sabre@nondot.org>
Tue, 14 Feb 2006 23:06:02 +0000 (23:06 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 14 Feb 2006 23:06:02 +0000 (23:06 +0000)
can provide work for the outer loop to canonicalize.

This fixes a case that breaks unswitching.

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

lib/Transforms/Utils/LoopSimplify.cpp

index a41692b4c26a07d1dc500bc660dad3b02bc91087..3188f123b7fb86769dd6f046aef443ceba8bb9c6 100644 (file)
@@ -115,7 +115,11 @@ bool LoopSimplify::runOnFunction(Function &F) {
 ///
 bool LoopSimplify::ProcessLoop(Loop *L) {
   bool Changed = false;
-
+  // Canonicalize inner loops before outer loops.  Inner loop canonicalization
+  // can provide work for the outer loop to canonicalize.
+  for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
+    Changed |= ProcessLoop(*I);
+  
   // Check to see that no blocks (other than the header) in the loop have
   // predecessors that are not in the loop.  This is not valid for natural
   // loops, but can occur if the blocks are unreachable.  Since they are
@@ -205,9 +209,6 @@ bool LoopSimplify::ProcessLoop(Loop *L) {
         PN->eraseFromParent();
       }
 
-  for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
-    Changed |= ProcessLoop(*I);
-
   return Changed;
 }