diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 729173df6355f1..00976d44b66523 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -2429,14 +2429,15 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) { // Okay, we do not know the exit count here. Can we at least prove that it // will remain the same within iteration space? auto *BI = cast(ExitingBB->getTerminator()); - auto OptimizeCond = [&](bool Inverted) { - if (isTrivialCond(L, BI, SE, Inverted, MaxExitCount)) { + auto OptimizeCond = [&](bool Inverted, const SCEV *MaxIter) { + if (isTrivialCond(L, BI, SE, Inverted, MaxIter)) { FoldExit(ExitingBB, Inverted); return true; } return false; }; - if (OptimizeCond(false) || OptimizeCond(true)) + if (OptimizeCond(false, MaxExitCount) || + OptimizeCond(true, MaxExitCount)) Changed = true; continue; }