@@ -4084,7 +4084,6 @@ static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
40844084 case VPDef::VPEVLBasedIVPHISC:
40854085 case VPDef::VPPredInstPHISC:
40864086 case VPDef::VPBranchOnMaskSC:
4087- case VPDef::VPMonotonicPHISC:
40884087 continue ;
40894088 case VPDef::VPReductionSC:
40904089 case VPDef::VPActiveLaneMaskPHISC:
@@ -8115,7 +8114,7 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
81158114 if ((Recipe = tryToOptimizeInductionPHI (Phi, Operands, Range)))
81168115 return Recipe;
81178116
8118- VPHeaderPHIRecipe *PhiRecipe = nullptr ;
8117+ VPSingleDefRecipe *PhiRecipe = nullptr ;
81198118 assert ((Legal->isMonotonicPHI (Phi) || Legal->isReductionVariable (Phi) ||
81208119 Legal->isFixedOrderRecurrence (Phi)) &&
81218120 " can only widen monotonic phis, reductions and fixed-order "
@@ -8124,10 +8123,9 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
81248123 Value *IncomingVal =
81258124 Phi->getIncomingValueForBlock (OrigLoop->getLoopPreheader ());
81268125 if (Legal->isMonotonicPHI (Phi)) {
8127- const MonotonicDescriptor &Desc =
8128- Legal->getMonotonicPHIs ().find (Phi)->second ;
8129- assert (Desc.getExpr ()->getStart () == PSE.getSCEV (IncomingVal));
8130- PhiRecipe = new VPMonotonicPHIRecipe (Phi, Desc, StartV);
8126+ PhiRecipe = new VPPhi ({StartV}, Phi->getDebugLoc (),
8127+ Phi->getName () + " .monotonic" );
8128+ PhiRecipe->setUnderlyingValue (Phi);
81318129 } else if (Legal->isReductionVariable (Phi)) {
81328130 const RecurrenceDescriptor &RdxDesc = Legal->getRecurrenceDescriptor (Phi);
81338131 assert (RdxDesc.getRecurrenceStartValue () ==
@@ -8480,10 +8478,19 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
84808478 // ---------------------------------------------------------------------------
84818479
84828480 // Adjust the recipes for any monotonic phis.
8481+ auto &MonotonicPHIs = Legal->getMonotonicPHIs ();
84838482 for (VPRecipeBase &R : HeaderVPBB->phis ()) {
8484- auto *MonotonicPhi = dyn_cast<VPMonotonicPHIRecipe >(&R);
8483+ auto *MonotonicPhi = dyn_cast<VPPhi >(&R);
84858484 if (!MonotonicPhi)
84868485 continue ;
8486+ assert (MonotonicPhi->getNumIncoming () == 2 &&
8487+ MonotonicPhi->getIncomingBlock (0 ) == Plan->getVectorPreheader ());
8488+
8489+ auto It =
8490+ MonotonicPHIs.find (cast<PHINode>(MonotonicPhi->getUnderlyingValue ()));
8491+ if (It == MonotonicPHIs.end ())
8492+ continue ;
8493+ auto &Desc = It->second ;
84878494
84888495 // Prohibit scalarization of monotonic phis.
84898496 if (!all_of (Range, [&](ElementCount VF) {
@@ -8494,7 +8501,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
84948501
84958502 // Obtain mask value for the predicate edge from the last VPBlendRecipe in
84968503 // chain.
8497- VPValue *Chain = MonotonicPhi->getBackedgeValue ( );
8504+ VPValue *Chain = MonotonicPhi->getIncomingValue ( 1 );
84988505 VPValue *Mask = nullptr ;
84998506 while (auto *BlendR = dyn_cast<VPBlendRecipe>(Chain))
85008507 for (unsigned I = 0 , E = BlendR->getNumIncomingValues (); I != E; ++I)
@@ -8506,17 +8513,17 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
85068513 }
85078514 assert (Mask);
85088515
8509- auto &Desc = MonotonicPhi->getDescriptor ();
85108516 auto &SE = *PSE.getSE ();
85118517 auto *Step = vputils::getOrCreateVPValueForSCEVExpr (
85128518 *Plan, Desc.getExpr ()->getStepRecurrence (SE));
85138519
85148520 auto *MonotonicI =
85158521 new VPInstruction (VPInstruction::ComputeMonotonicResult,
85168522 {MonotonicPhi, Mask, Step}, *Desc.getStepInst ());
8517- auto *InsertBlock = MonotonicPhi->getBackedgeRecipe ().getParent ();
8523+ auto *BackedgeVal = MonotonicPhi->getIncomingValue (1 );
8524+ auto *InsertBlock = BackedgeVal->getDefiningRecipe ()->getParent ();
85188525 InsertBlock->insert (MonotonicI, InsertBlock->getFirstNonPhi ());
8519- MonotonicPhi-> getBackedgeValue () ->replaceAllUsesWith (MonotonicI);
8526+ BackedgeVal ->replaceAllUsesWith (MonotonicI);
85208527 }
85218528
85228529 // Adjust the recipes for any inloop reductions.
0 commit comments