@@ -9337,10 +9337,10 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
93379337 VPBasicBlock::iterator MBIP = MiddleVPBB->getFirstNonPhi ();
93389338 VPBlockBase *PrevVPBB = nullptr ;
93399339 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
9340- // Skip VPBBs not corresponding to any input IR basic blocks .
9341- if (!HCFGBuilder. getIRBBForVPB ( VPBB)) {
9342- assert (VPBB == LoopRegion-> getExiting ( ) &&
9343- " only the latch block shouldn't have a corresponding IRBB" );
9340+ // Handle VPBBs down to the latch .
9341+ if (VPBB == LoopRegion-> getExiting ( )) {
9342+ assert (!HCFGBuilder. getIRBBForVPB (VPBB ) &&
9343+ " the latch block shouldn't have a corresponding IRBB" );
93449344 VPBlockUtils::connectBlocks (PrevVPBB, VPBB);
93459345 break ;
93469346 }
@@ -9358,15 +9358,18 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
93589358 // Convert input VPInstructions to widened recipes.
93599359 for (VPRecipeBase &R : make_early_inc_range (*VPBB)) {
93609360 auto *SingleDef = cast<VPSingleDefRecipe>(&R);
9361+ auto *UnderlyingValue = SingleDef->getUnderlyingValue ();
93619362 // Skip recipes that do not need transforming, including canonical IV,
93629363 // wide canonical IV and VPInstructions without underlying values. The
9363- // latter is added by masking.
9364- if (isa<VPCanonicalIVPHIRecipe>(SingleDef) ||
9365- isa<VPWidenCanonicalIVRecipe>(SingleDef) ||
9366- (isa<VPInstruction>(&R) && !SingleDef-> getUnderlyingValue () ))
9364+ // latter are added above by masking.
9365+ // FIXME: Migrate code relying on the underlying instruction from VPlan0 to construct recipes below to not use the underlying instruction.
9366+ if ( isa<VPCanonicalIVPHIRecipe, VPWidenCanonicalIVRecipe>(SingleDef) ||
9367+ (isa<VPInstruction>(&R) && !UnderlyingValue ))
93679368 continue ;
9368- assert (isa<VPWidenPHIRecipe>(&R) || (isa<VPInstruction>(SingleDef) &&
9369- SingleDef->getUnderlyingValue ()) &&
9369+
9370+ // FIXME: VPlan0, which models a copy of the original scalar loop, should not use VPWidenPHIRecipe to model the phis.
9371+ assert ((isa<VPWidenPHIRecipe>(SingleDef) || isa<VPInstruction>(SingleDef)) &&
9372+ UnderlyingValue &&
93709373 " unsupported recipe" );
93719374
93729375 if (match (&R, m_BranchOnCond (m_VPValue ())) ||
@@ -9378,11 +9381,12 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
93789381
93799382 // TODO: Gradually replace uses of underlying instruction by analyses on
93809383 // VPlan.
9381- Instruction *Instr = SingleDef-> getUnderlyingInstr ( );
9384+ Instruction *Instr = cast<Instruction>(UnderlyingValue );
93829385 Builder.setInsertPoint (SingleDef);
93839386 SmallVector<VPValue *, 4 > Operands;
93849387 auto *Phi = dyn_cast<PHINode>(Instr);
93859388 if (Phi && Phi->getParent () == HeaderBB) {
9389+ // The backedge value will be added in fixHeaderPhis later.
93869390 Operands.push_back (Plan->getOrAddLiveIn (
93879391 Phi->getIncomingValueForBlock (OrigLoop->getLoopPreheader ())));
93889392 } else {
@@ -9414,11 +9418,11 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
94149418
94159419 RecipeBuilder.setRecipe (Instr, Recipe);
94169420 if (isa<VPWidenIntOrFpInductionRecipe>(Recipe) && isa<TruncInst>(Instr)) {
9417- // Optimized a truncate truncates to VPWidenIntOrFpInductionRecipe Move
9418- // it to the phi section in the header.
9421+ // Optimized a truncate to VPWidenIntOrFpInductionRecipe. It needs to be moved to the phi section in the header.
94199422 Recipe->insertBefore (*HeaderVPBB, HeaderVPBB->getFirstNonPhi ());
9420- } else
9423+ } else {
94219424 Builder.insert (Recipe);
9425+ }
94229426 if (Recipe->getNumDefinedValues () == 1 )
94239427 SingleDef->replaceAllUsesWith (Recipe->getVPSingleValue ());
94249428 else
@@ -9429,8 +9433,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
94299433
94309434 // Flatten the CFG in the loop. Masks for blocks have already been generated
94319435 // and added to recipes as needed. To do so, first disconnect VPBB from its
9432- // predecessors and successors. Then connect VPBB to the previously visited
9433- // VPBB.
9436+ // successors. Then connect VPBB to the previously visited$ VPBB.
94349437 for (auto *Succ : to_vector (VPBB->getSuccessors ()))
94359438 VPBlockUtils::disconnectBlocks (VPBB, Succ);
94369439 if (PrevVPBB)
0 commit comments