Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -9503,7 +9503,18 @@ bool ScalarEvolution::isKnownPredicateAt(ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, const Instruction *Context) { - // TODO: Analyze guards and assumes from Context's block. + // Check conditions due to any @llvm.assume intrinsics. + for (auto &AssumeVH : AC.assumptions()) { + if (!AssumeVH) + continue; + auto *CI = cast(AssumeVH); + if (!DT.dominates(CI, Context)) + continue; + + if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false, Context)) + return true; + } + return isKnownPredicate(Pred, LHS, RHS) || isBasicBlockEntryGuardedByCond(Context->getParent(), Pred, LHS, RHS); } @@ -9890,18 +9901,6 @@ return true; } - // Check conditions due to any @llvm.assume intrinsics. - for (auto &AssumeVH : AC.assumptions()) { - if (!AssumeVH) - continue; - auto *CI = cast(AssumeVH); - if (!DT.dominates(CI, Latch->getTerminator())) - continue; - - if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false)) - return true; - } - // If the loop is not reachable from the entry block, we risk running into an // infinite loop as we walk up into the dom tree. These loops do not matter // anyway, so we just return a conservative answer when we see them.