Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -6701,11 +6701,12 @@ BasicBlock *LoopLatch = L->getLoopLatch(); - // TODO: Can we do something for greater than and less than? - // Terminating condition is foldable when it is an eq/ne icmp - BranchInst *BI = cast(LoopLatch->getTerminator()); - if (BI->isUnconditional()) + BranchInst *BI = dyn_cast(LoopLatch->getTerminator()); + if (!BI || BI->isUnconditional()) { + LLVM_DEBUG(dbgs() << "Cannot fold terminator that is not a conditional " + "branch instruction") return std::nullopt; + } auto *TermCond = dyn_cast(BI->getCondition()); if (!TermCond) { LLVM_DEBUG(