[ShrinkWrapping] Fix an infinite loop while looking for restore point.
[oota-llvm.git] / lib / CodeGen / ShrinkWrap.cpp
index 7e2f15163cb4babc02390d66d49f0b7041aed2fc..c406c149c0071a5a8443f74c0f9f87b263ce02ab 100644 (file)
@@ -309,6 +309,14 @@ void ShrinkWrap::updateSaveRestorePoints(MachineBasicBlock &MBB) {
         }
       }
       else {
+        // If the loop does not exit, there is no point in looking
+        // for a post-dominator outside the loop.
+        SmallVector<MachineBasicBlock*, 4> ExitBlocks;
+        MLI->getLoopFor(Restore)->getExitingBlocks(ExitBlocks);
+        if (ExitBlocks.empty()) {
+          Restore = nullptr;
+          break;
+        }
         // Push Restore outside of this loop if immediate post-dominator is
         // different from restore block. If immediate post-dominator is not
         // different, bail out.