Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -10702,18 +10702,27 @@ return false; } - // Unsigned comparison is the same as signed comparison when both the operands - // are non-negative or negative. auto IsSignFlippedPredicate = [](CmpInst::Predicate P1, CmpInst::Predicate P2) { assert(P1 != P2 && "Handled earlier!"); return CmpInst::isRelational(P2) && P1 == CmpInst::getFlippedSignednessPredicate(P2); }; - if (IsSignFlippedPredicate(Pred, FoundPred) && - ((isKnownNonNegative(FoundLHS) && isKnownNonNegative(FoundRHS)) || - (isKnownNegative(FoundLHS) && isKnownNegative(FoundRHS)))) - return isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS, CtxI); + if (IsSignFlippedPredicate(Pred, FoundPred)) { + // Unsigned comparison is the same as signed comparison when both the + // operands are non-negative or negative. + if ((isKnownNonNegative(FoundLHS) && isKnownNonNegative(FoundRHS)) || + (isKnownNegative(FoundLHS) && isKnownNegative(FoundRHS))) + return isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS, CtxI); + // TODO: A symmetrical fact should be provable for replacing an unsigned + // predicate with signed. + if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE) + if (isKnownNonNegative(RHS)) + // We need to prove that LHS