diff --git a/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp b/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp index 9f338dbc78cff..1163bfa5b795d 100644 --- a/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp +++ b/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp @@ -150,6 +150,10 @@ static bool unifyLoopExits(DominatorTree &DT, LoopInfo &LI, Loop *L) { SmallVector ExitingBlocks; L->getExitingBlocks(ExitingBlocks); + // No exit blocks, so nothing to do. Just return. + if (ExitingBlocks.empty()) + return false; + // Redirect exiting edges through a control flow hub. ControlFlowHub CHub; for (auto *BB : ExitingBlocks) { diff --git a/llvm/test/Transforms/Util/pr165252.ll b/llvm/test/Transforms/Util/pr165252.ll new file mode 100644 index 0000000000000..bab1a23c6ce57 --- /dev/null +++ b/llvm/test/Transforms/Util/pr165252.ll @@ -0,0 +1,15 @@ +; REQUIRES: asserts +; RUN: opt -passes=unify-loop-exits -S %s + +define void @test() { +entry: + br i1 true, label %end, label %Loop + +Loop: + %V = phi i32 [0, %entry], [%V1, %Loop] + %V1 = add i32 %V, 1 + br label %Loop + +end: + ret void +}