@@ -2444,19 +2444,20 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
24442444 ScalarEvolution &SE = *PSE.getSE ();
24452445 // TODO: Emit unconditional branch to vector preheader instead of
24462446 // conditional branch with known condition.
2447- const SCEV *TripCountSCEV = SE.getSCEV (Count);
2447+ const SCEV *TripCountSCEV = SE.applyLoopGuards (SE. getSCEV (Count), OrigLoop );
24482448 // Check if the trip count is < the step.
2449- if (SE.isKnownPredicate (P, SE.applyLoopGuards (TripCountSCEV, OrigLoop),
2450- SE.getSCEV (Step))) {
2451- // TODO: Should not attempt to vectorize when the vector loop is known to
2452- // never execute.
2449+ if (SE.isKnownPredicate (P, TripCountSCEV, SE.getSCEV (Step))) {
2450+ // TODO: Ensure step is at most the trip count when determining max VF and
2451+ // UF, w/o tail folding.
24532452 CheckMinIters = Builder.getTrue ();
24542453 } else if (!SE.isKnownPredicate (CmpInst::getInversePredicate (P),
2455- SE.applyLoopGuards (TripCountSCEV, OrigLoop),
2456- SE.getSCEV (Step))) {
2457- // Only generate the minimum iteration check only if we cannot prove the
2458- // check is known to be false.
2454+ TripCountSCEV, SE.getSCEV (Step))) {
2455+ // Generate the minimum iteration check only if we cannot prove the
2456+ // check is known to be true, or known to be false
24592457 CheckMinIters = Builder.CreateICmp (P, Count, Step, " min.iters.check" );
2458+
2459+ // else step is known to be smaller than trip count, use CheckMinIters
2460+ // preset to false.
24602461 }
24612462 } else if (VF.isScalable () &&
24622463 !isIndvarOverflowCheckKnownFalse (Cost, VF, UF) &&
@@ -2473,12 +2474,11 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
24732474 Value *Step = CreateStep ();
24742475 ScalarEvolution &SE = *PSE.getSE ();
24752476 // Check if we can prove that the trip count is >= the step.
2476- // TODO: Emit unconditional branch to vector preheader instead of
2477- // conditional branch with known condition.
2478- const SCEV *TripCountSCEV = SE.getSCEV (LHS);
2479- assert (!SE.isKnownPredicate (CmpInst::getInversePredicate (ICmpInst::ICMP_ULT),
2480- SE.applyLoopGuards (TripCountSCEV, OrigLoop),
2481- SE.getSCEV (Step)) && " SCEV unexpectedly proved overflow check to be known);
2477+ const SCEV *TripCountSCEV = SE.applyLoopGuards (SE.getSCEV (LHS), OrigLoop);
2478+ assert (
2479+ !SE.isKnownPredicate (CmpInst::getInversePredicate (ICmpInst::ICMP_ULT),
2480+ TripCountSCEV, SE.getSCEV (Step)) &&
2481+ " SCEV unexpectedly proved overflow check to be known" );
24822482 // Don't execute the vector loop if (UMax - n) < (VF * UF).
24832483 CheckMinIters = Builder.CreateICmp (ICmpInst::ICMP_ULT, LHS, Step);
24842484 }
0 commit comments