@@ -2443,16 +2443,22 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
24432443 if (Style == TailFoldingStyle::None) {
24442444 Value *Step = CreateStep ();
24452445 ScalarEvolution &SE = *PSE.getSE ();
2446- // Check if we can prove that the trip count is >= the step.
24472446 // TODO: Emit unconditional branch to vector preheader instead of
24482447 // conditional branch with known condition.
24492448 const SCEV *TripCountSCEV = SE.getSCEV (Count);
2450- if (SE.isKnownPredicate (CmpInst::getInversePredicate (P),
2451- SE.applyLoopGuards (TripCountSCEV, OrigLoop),
2452- SE.getSCEV (Step)))
2453- CheckMinIters = Builder.getFalse ();
2454- else
2449+ // Check if the trip count is < the step.
2450+ if (SE.isKnownPredicate (P, SE.applyLoopGuards (TripCountSCEV, OrigLoop),
2451+ SE.getSCEV (Step))) {
2452+ // TODO: Should not attempt to vectorize when the vector loop is known to
2453+ // never execute.
2454+ CheckMinIters = Builder.getTrue ();
2455+ } else if (!SE.isKnownPredicate (CmpInst::getInversePredicate (P),
2456+ SE.applyLoopGuards (TripCountSCEV, OrigLoop),
2457+ SE.getSCEV (Step))) {
2458+ // Only generate the minimum iteration check only if we cannot prove the
2459+ // check is known to be false.
24552460 CheckMinIters = Builder.CreateICmp (P, Count, Step, " min.iters.check" );
2461+ }
24562462 } else if (VF.isScalable () &&
24572463 !isIndvarOverflowCheckKnownFalse (Cost, VF, UF) &&
24582464 Style != TailFoldingStyle::DataAndControlFlowWithoutRuntimeCheck) {
@@ -2465,8 +2471,17 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
24652471 ConstantInt::get (CountTy, cast<IntegerType>(CountTy)->getMask ());
24662472 Value *LHS = Builder.CreateSub (MaxUIntTripCount, Count);
24672473
2474+ Value *Step = CreateStep ();
2475+ ScalarEvolution &SE = *PSE.getSE ();
2476+ // Check if we can prove that the trip count is >= the step.
2477+ // TODO: Emit unconditional branch to vector preheader instead of
2478+ // conditional branch with known condition.
2479+ const SCEV *TripCountSCEV = SE.getSCEV (LHS);
2480+ assert (!SE.isKnownPredicate (CmpInst::getInversePredicate (ICmpInst::ICMP_ULT),
2481+ SE.applyLoopGuards (TripCountSCEV, OrigLoop),
2482+ SE.getSCEV (Step)) && " SCEV unexpectedly proved overflow check to be known);
24682483 // Don't execute the vector loop if (UMax - n) < (VF * UF).
2469- CheckMinIters = Builder.CreateICmp (ICmpInst::ICMP_ULT, LHS, CreateStep () );
2484+ CheckMinIters = Builder.CreateICmp(ICmpInst::ICMP_ULT, LHS, Step );
24702485 }
24712486
24722487 // Create new preheader for vector loop.
0 commit comments