@@ -8538,36 +8538,30 @@ VPWidenIntOrFpInductionRecipe *VPRecipeBuilder::tryToOptimizeInductionTruncate(
85388538 return nullptr ;
85398539}
85408540
8541- VPBlendRecipe *VPRecipeBuilder::tryToBlend (PHINode *Phi,
8542- ArrayRef<VPValue *> Operands) {
8543- unsigned NumIncoming = Phi->getNumIncomingValues ();
8541+ VPBlendRecipe *VPRecipeBuilder::tryToBlend (VPWidenPHIRecipe *PhiR) {
8542+ unsigned NumIncoming = PhiR->getNumIncoming ();
85448543
85458544 // We know that all PHIs in non-header blocks are converted into selects, so
85468545 // we don't have to worry about the insertion order and we can just use the
85478546 // builder. At this point we generate the predication tree. There may be
85488547 // duplications since this is a simple recursive scan, but future
85498548 // optimizations will clean it up.
85508549
8551- // Map incoming IR BasicBlocks to incoming VPValues, for lookup below.
8552- // TODO: Add operands and masks in order from the VPlan predecessors.
8553- DenseMap<BasicBlock *, VPValue *> VPIncomingValues;
8554- for (const auto &[Idx, Pred] : enumerate(predecessors (Phi->getParent ())))
8555- VPIncomingValues[Pred] = Operands[Idx];
8556-
85578550 SmallVector<VPValue *, 2 > OperandsWithMask;
85588551 for (unsigned In = 0 ; In < NumIncoming; In++) {
8559- BasicBlock *Pred = Phi ->getIncomingBlock (In);
8560- OperandsWithMask.push_back (VPIncomingValues. lookup (Pred ));
8561- VPValue *EdgeMask = getEdgeMask (Pred, Phi ->getParent ());
8552+ const VPBasicBlock *Pred = PhiR ->getIncomingBlock (In);
8553+ OperandsWithMask.push_back (PhiR-> getIncomingValue (In ));
8554+ VPValue *EdgeMask = getEdgeMask (Pred, PhiR ->getParent ());
85628555 if (!EdgeMask) {
85638556 assert (In == 0 && " Both null and non-null edge masks found" );
8564- assert (all_equal (Operands ) &&
8557+ assert (all_equal (PhiR-> operands () ) &&
85658558 " Distinct incoming values with one having a full mask" );
85668559 break ;
85678560 }
85688561 OperandsWithMask.push_back (EdgeMask);
85698562 }
8570- return new VPBlendRecipe (Phi, OperandsWithMask);
8563+ return new VPBlendRecipe (cast<PHINode>(PhiR->getUnderlyingInstr ()),
8564+ OperandsWithMask);
85718565}
85728566
85738567VPSingleDefRecipe *VPRecipeBuilder::tryToWidenCall (CallInst *CI,
@@ -8954,15 +8948,18 @@ bool VPRecipeBuilder::getScaledReductions(
89548948 return false ;
89558949}
89568950
8957- VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe (
8958- Instruction *Instr, ArrayRef<VPValue *> Operands, VFRange &Range) {
8951+ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe (VPSingleDefRecipe *R,
8952+ VFRange &Range) {
89598953 // First, check for specific widening recipes that deal with inductions, Phi
89608954 // nodes, calls and memory operations.
89618955 VPRecipeBase *Recipe;
8962- if (auto *Phi = dyn_cast<PHINode>(Instr)) {
8963- if (Phi->getParent () != OrigLoop->getHeader ())
8964- return tryToBlend (Phi, Operands);
8956+ Instruction *Instr = R->getUnderlyingInstr ();
8957+ SmallVector<VPValue *, 4 > Operands (R->operands ());
8958+ if (auto *PhiR = dyn_cast<VPWidenPHIRecipe>(R)) {
8959+ if (PhiR->getParent ()->getNumPredecessors () != 0 )
8960+ return tryToBlend (PhiR);
89658961
8962+ auto *Phi = cast<PHINode>(R->getUnderlyingInstr ());
89668963 assert (Operands.size () == 2 && " Must have 2 operands for header phis" );
89678964 if ((Recipe = tryToOptimizeInductionPHI (Phi, Operands, Range)))
89688965 return Recipe;
@@ -9526,11 +9523,12 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
95269523 continue ;
95279524 }
95289525
9529- SmallVector<VPValue *, 4 > Operands (R.operands ());
95309526 VPRecipeBase *Recipe =
9531- RecipeBuilder.tryToCreateWidenRecipe (Instr, Operands, Range);
9532- if (!Recipe)
9527+ RecipeBuilder.tryToCreateWidenRecipe (SingleDef, Range);
9528+ if (!Recipe) {
9529+ SmallVector<VPValue *, 4 > Operands (R.operands ());
95339530 Recipe = RecipeBuilder.handleReplication (Instr, Operands, Range);
9531+ }
95349532
95359533 RecipeBuilder.setRecipe (Instr, Recipe);
95369534 if (isa<VPWidenIntOrFpInductionRecipe>(Recipe) && isa<TruncInst>(Instr)) {
0 commit comments