Make sure the immediate dominator isn't NULL through iterations
authorEric Christopher <echristo@apple.com>
Thu, 10 Dec 2009 00:25:41 +0000 (00:25 +0000)
committerEric Christopher <echristo@apple.com>
Thu, 10 Dec 2009 00:25:41 +0000 (00:25 +0000)
of the loop. We could get to this condition via indirect
branches.

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

lib/Transforms/Scalar/LICM.cpp

index 5511387c8da406ceca658a31b14817dc2874b623..42a8fdc6aa85ab2562200208eefbce1084091c79 100644 (file)
@@ -160,16 +160,17 @@ namespace {
 
       // Because the exit block is not in the loop, we know we have to get _at
       // least_ its immediate dominator.
-      do {
-        // Get next Immediate Dominator.
-        IDom = IDom->getIDom();
-
+      IDom = IDom->getIDom();
+      
+      while (IDom && IDom != BlockInLoopNode) {
         // If we have got to the header of the loop, then the instructions block
         // did not dominate the exit node, so we can't hoist it.
         if (IDom->getBlock() == LoopHeader)
           return false;
 
-      } while (IDom != BlockInLoopNode);
+        // Get next Immediate Dominator.
+        IDom = IDom->getIDom();
+      };
 
       return true;
     }