diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -778,8 +778,9 @@ /// Checks if \p L has single exit through latch block except possibly -/// "deoptimizing" exits. Returns branch instruction terminating the loop -/// latch if above check is successful, nullptr otherwise. +/// "deoptimizing" (@llvm.experimental.deoptimize or unreachable-terminated) +/// exits. Returns branch instruction terminating the loop latch if above check +/// is successful, nullptr otherwise. static BranchInst *getExpectedExitLoopLatchBranch(Loop *L) { BasicBlock *Latch = L->getLoopLatch(); if (!Latch) @@ -795,8 +796,9 @@ SmallVector ExitBlocks; L->getUniqueNonLatchExitBlocks(ExitBlocks); - if (any_of(ExitBlocks, [](const BasicBlock *EB) { - return !EB->getTerminatingDeoptimizeCall(); + SmallVector DeoptimizingBlocks; + if (any_of(ExitBlocks, [&](const BasicBlock *EB) { + return !IsBlockDeoptimizing(EB, DeoptimizingBlocks); })) return nullptr;