@@ -2382,13 +2382,18 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan) {
23822382void VPlanTransforms::handleUncountableEarlyExit (
23832383 VPlan &Plan, ScalarEvolution &SE, Loop *OrigLoop,
23842384 BasicBlock *UncountableExitingBlock, VPRecipeBuilder &RecipeBuilder,
2385- const VFRange &Range) {
2385+ VFRange &Range) {
23862386 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion ();
23872387 auto *LatchVPBB = cast<VPBasicBlock>(LoopRegion->getExiting ());
23882388 VPBuilder Builder (LatchVPBB->getTerminator ());
23892389 auto *MiddleVPBB = Plan.getMiddleBlock ();
23902390 VPValue *IsEarlyExitTaken = nullptr ;
23912391
2392+ // Clamp the range that make sure we insert extractElement for incoming value
2393+ // correctly.
2394+ bool IsScalarVF = LoopVectorizationPlanner::getDecisionAndClampRange (
2395+ [&](ElementCount VF) { return VF.isScalar (); }, Range);
2396+
23922397 // Process the uncountable exiting block. Update IsEarlyExitTaken, which
23932398 // tracks if the uncountable early exit has been taken. Also split the middle
23942399 // block and have it conditionally branch to the early exit block if
@@ -2438,7 +2443,7 @@ void VPlanTransforms::handleUncountableEarlyExit(
24382443 ExitIRI->extractLastLaneOfOperand (MiddleBuilder);
24392444 }
24402445 // Add the incoming value from the early exit.
2441- if (!IncomingFromEarlyExit->isLiveIn () && !Range. Start . isScalar () ) {
2446+ if (!IncomingFromEarlyExit->isLiveIn () && !IsScalarVF ) {
24422447 VPValue *FirstActiveLane = EarlyExitB.createNaryOp (
24432448 VPInstruction::FirstActiveLane, {EarlyExitTakenCond}, nullptr ,
24442449 " first.active.lane" );
0 commit comments