From dc29c973e5c8e3f1dfb6ea83570e4ee571008ca5 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Tue, 15 Sep 2015 18:19:39 +0000 Subject: [ShrinkWrapping] Fix an infinite loop while looking for restore point. This may happen when the input program itself contains an infinite loop with no exit block. In that case, we would fail to find a block post-dominating the loop such that this block is outside of the loop. This fixes PR24823. Working on reducing the test case. llvm-svn: 247710 --- llvm/lib/CodeGen/ShrinkWrap.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/ShrinkWrap.cpp b/llvm/lib/CodeGen/ShrinkWrap.cpp index 7e2f15163cb..c406c149c00 100644 --- a/llvm/lib/CodeGen/ShrinkWrap.cpp +++ b/llvm/lib/CodeGen/ShrinkWrap.cpp @@ -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 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. -- cgit v1.2.3