diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -756,8 +756,13 @@ } // When completely unrolling, the last latch becomes unreachable. - if (!LatchIsExiting && CompletelyUnroll) - changeToUnreachable(Latches.back()->getTerminator(), PreserveLCSSA, &DTU); + if (!LatchIsExiting && CompletelyUnroll) { + // There is no need to update the DT here, because there must be a unique + // latch. Hence if the latch is not exiting it must directly branch back to + // the original loop header and does not dominate any nodes. + assert(LatchBlock->getSingleSuccessor() && "Loop with multiple latches?"); + changeToUnreachable(Latches.back()->getTerminator(), PreserveLCSSA); + } // Merge adjacent basic blocks, if possible. for (BasicBlock *Latch : Latches) {