[ShrinkWrap] Fix FindIDom to only have one kind of failure.
[oota-llvm.git] / lib / CodeGen / ShrinkWrap.cpp
index f8aa1e2b0b9a62b8138f357ae4719f3fde94c4d1..2ff86aaa51cd9f45bf2beaf154bb5798ddf476cd 100644 (file)
@@ -263,6 +263,8 @@ MachineBasicBlock *FindIDom(MachineBasicBlock &Block, ListOfBBs BBs,
     if (!IDom)
       break;
   }
+  if (IDom == &Block)
+    return nullptr;
   return IDom;
 }
 
@@ -352,13 +354,9 @@ void ShrinkWrap::updateSaveRestorePoints(MachineBasicBlock &MBB,
       if (MLI->getLoopDepth(Save) > MLI->getLoopDepth(Restore)) {
         // Push Save outside of this loop if immediate dominator is different
         // from save block. If immediate dominator is not different, bail out.
-        MachineBasicBlock *IDom = FindIDom<>(*Save, Save->predecessors(), *MDT);
-        if (IDom != Save)
-          Save = IDom;
-        else {
-          Save = nullptr;
+        Save = FindIDom<>(*Save, Save->predecessors(), *MDT);
+        if (!Save)
           break;
-        }
       } else {
         // If the loop does not exit, there is no point in looking
         // for a post-dominator outside the loop.