@@ -8539,10 +8539,7 @@ VPWidenIntOrFpInductionRecipe *VPRecipeBuilder::tryToOptimizeInductionTruncate(
85398539 return nullptr ;
85408540}
85418541
8542- VPBlendRecipe *VPRecipeBuilder::tryToBlend (PHINode *Phi,
8543- ArrayRef<VPValue *> Operands) {
8544- unsigned NumIncoming = Phi->getNumIncomingValues ();
8545-
8542+ VPBlendRecipe *VPRecipeBuilder::tryToBlend (VPWidenPHIRecipe *PhiR) {
85468543 // We know that all PHIs in non-header blocks are converted into selects, so
85478544 // we don't have to worry about the insertion order and we can just use the
85488545 // builder. At this point we generate the predication tree. There may be
@@ -8552,17 +8549,19 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi,
85528549 // Map incoming IR BasicBlocks to incoming VPValues, for lookup below.
85538550 // TODO: Add operands and masks in order from the VPlan predecessors.
85548551 DenseMap<BasicBlock *, VPValue *> VPIncomingValues;
8552+ auto *Phi = cast<PHINode>(PhiR->getUnderlyingInstr ());
85558553 for (const auto &[Idx, Pred] : enumerate(predecessors (Phi->getParent ())))
8556- VPIncomingValues[Pred] = Operands[ Idx] ;
8554+ VPIncomingValues[Pred] = PhiR-> getOperand ( Idx) ;
85578555
8556+ unsigned NumIncoming = PhiR->getNumIncoming ();
85588557 SmallVector<VPValue *, 2 > OperandsWithMask;
85598558 for (unsigned In = 0 ; In < NumIncoming; In++) {
85608559 BasicBlock *Pred = Phi->getIncomingBlock (In);
85618560 OperandsWithMask.push_back (VPIncomingValues.lookup (Pred));
85628561 VPValue *EdgeMask = getEdgeMask (Pred, Phi->getParent ());
85638562 if (!EdgeMask) {
85648563 assert (In == 0 && " Both null and non-null edge masks found" );
8565- assert (all_equal (Operands ) &&
8564+ assert (all_equal (PhiR-> operands () ) &&
85668565 " Distinct incoming values with one having a full mask" );
85678566 break ;
85688567 }
@@ -8955,15 +8954,21 @@ bool VPRecipeBuilder::getScaledReductions(
89558954 return false ;
89568955}
89578956
8958- VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe (
8959- Instruction *Instr, ArrayRef<VPValue *> Operands, VFRange &Range) {
8957+ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe (VPSingleDefRecipe *R,
8958+ VFRange &Range) {
89608959 // First, check for specific widening recipes that deal with inductions, Phi
89618960 // nodes, calls and memory operations.
89628961 VPRecipeBase *Recipe;
8963- if (auto *Phi = dyn_cast<PHINode>(Instr)) {
8964- if (Phi->getParent () != OrigLoop->getHeader ())
8965- return tryToBlend (Phi, Operands);
8966-
8962+ Instruction *Instr = R->getUnderlyingInstr ();
8963+ SmallVector<VPValue *, 4 > Operands (R->operands ());
8964+ if (auto *PhiR = dyn_cast<VPWidenPHIRecipe>(R)) {
8965+ VPBasicBlock *Parent = PhiR->getParent ();
8966+ VPRegionBlock *LoopRegionOf = Parent->getEnclosingLoopRegion ();
8967+ // Handle phis in non-header blocks.
8968+ if (!LoopRegionOf || LoopRegionOf->getEntry () != Parent)
8969+ return tryToBlend (PhiR);
8970+
8971+ auto *Phi = cast<PHINode>(R->getUnderlyingInstr ());
89678972 assert (Operands.size () == 2 && " Must have 2 operands for header phis" );
89688973 if ((Recipe = tryToOptimizeInductionPHI (Phi, Operands, Range)))
89698974 return Recipe;
@@ -9528,11 +9533,12 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
95289533 continue ;
95299534 }
95309535
9531- SmallVector<VPValue *, 4 > Operands (R.operands ());
95329536 VPRecipeBase *Recipe =
9533- RecipeBuilder.tryToCreateWidenRecipe (Instr, Operands, Range);
9534- if (!Recipe)
9537+ RecipeBuilder.tryToCreateWidenRecipe (SingleDef, Range);
9538+ if (!Recipe) {
9539+ SmallVector<VPValue *, 4 > Operands (R.operands ());
95359540 Recipe = RecipeBuilder.handleReplication (Instr, Operands, Range);
9541+ }
95369542
95379543 RecipeBuilder.setRecipe (Instr, Recipe);
95389544 if (isa<VPWidenIntOrFpInductionRecipe>(Recipe) && isa<TruncInst>(Instr)) {
0 commit comments