@@ -7578,7 +7578,7 @@ VPWidenMemoryRecipe *VPRecipeBuilder::tryToWidenMemory(VPInstruction *VPI,
75787578
75797579 VPValue *Mask = nullptr ;
75807580 if (Legal->isMaskRequired (I))
7581- Mask = getBlockInMask ( Builder.getInsertBlock ());
7581+ Mask = Builder.getInsertBlock ()-> getEntryMask ( );
75827582
75837583 // Determine if the pointer operand of the access is either consecutive or
75847584 // reverse consecutive.
@@ -7791,7 +7791,7 @@ VPSingleDefRecipe *VPRecipeBuilder::tryToWidenCall(VPInstruction *VPI,
77917791 // all-true mask.
77927792 VPValue *Mask = nullptr ;
77937793 if (Legal->isMaskRequired (CI))
7794- Mask = getBlockInMask ( Builder.getInsertBlock ());
7794+ Mask = Builder.getInsertBlock ()-> getEntryMask ( );
77957795 else
77967796 Mask = Plan.getOrAddLiveIn (
77977797 ConstantInt::getTrue (IntegerType::getInt1Ty (Plan.getContext ())));
@@ -7834,7 +7834,7 @@ VPWidenRecipe *VPRecipeBuilder::tryToWiden(VPInstruction *VPI) {
78347834 // div/rem operation itself. Otherwise fall through to general handling below.
78357835 if (CM.isPredicatedInst (I)) {
78367836 SmallVector<VPValue *> Ops (VPI->operands ());
7837- VPValue *Mask = getBlockInMask ( Builder.getInsertBlock ());
7837+ VPValue *Mask = Builder.getInsertBlock ()-> getEntryMask ( );
78387838 VPValue *One = Plan.getConstantInt (I->getType (), 1u );
78397839 auto *SafeRHS =
78407840 Builder.createSelect (Mask, Ops[1 ], One, VPI->getDebugLoc ());
@@ -7914,7 +7914,7 @@ VPHistogramRecipe *VPRecipeBuilder::tryToWidenHistogram(const HistogramInfo *HI,
79147914 // In case of predicated execution (due to tail-folding, or conditional
79157915 // execution, or both), pass the relevant mask.
79167916 if (Legal->isMaskRequired (HI->Store ))
7917- HGramOps.push_back (getBlockInMask ( Builder.getInsertBlock ()));
7917+ HGramOps.push_back (Builder.getInsertBlock ()-> getEntryMask ( ));
79187918
79197919 return new VPHistogramRecipe (Opcode, HGramOps, VPI->getDebugLoc ());
79207920}
@@ -7968,7 +7968,7 @@ VPReplicateRecipe *VPRecipeBuilder::handleReplication(VPInstruction *VPI,
79687968 // added initially. Masked replicate recipes will later be placed under an
79697969 // if-then construct to prevent side-effects. Generate recipes to compute
79707970 // the block mask for this region.
7971- BlockInMask = getBlockInMask ( Builder.getInsertBlock ());
7971+ BlockInMask = Builder.getInsertBlock ()-> getEntryMask ( );
79727972 }
79737973
79747974 // Note that there is some custom logic to mark some intrinsics as uniform
@@ -8302,7 +8302,7 @@ VPRecipeBuilder::tryToCreatePartialReduction(VPInstruction *Reduction,
83028302
83038303 VPValue *Cond = nullptr ;
83048304 if (CM.blockNeedsPredicationForAnyReason (ReductionI->getParent ()))
8305- Cond = getBlockInMask ( Builder.getInsertBlock ());
8305+ Cond = Builder.getInsertBlock ()-> getEntryMask ( );
83068306 return new VPPartialReductionRecipe (ReductionOpcode, Accumulator, BinOp, Cond,
83078307 ScaleFactor, ReductionI);
83088308}
@@ -8426,15 +8426,14 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
84268426 // ---------------------------------------------------------------------------
84278427 // Predicate and linearize the top-level loop region.
84288428 // ---------------------------------------------------------------------------
8429- auto BlockMaskCache = VPlanTransforms::introduceMasksAndLinearize (
8430- *Plan, CM.foldTailByMasking ());
8429+ VPlanTransforms::introduceMasksAndLinearize (*Plan, CM.foldTailByMasking ());
84318430
84328431 // ---------------------------------------------------------------------------
84338432 // Construct wide recipes and apply predication for original scalar
84348433 // VPInstructions in the loop.
84358434 // ---------------------------------------------------------------------------
84368435 VPRecipeBuilder RecipeBuilder (*Plan, OrigLoop, TLI, &TTI, Legal, CM, PSE,
8437- Builder, BlockMaskCache );
8436+ Builder);
84388437 // TODO: Handle partial reductions with EVL tail folding.
84398438 if (!CM.foldTailWithEVL ())
84408439 RecipeBuilder.collectScaledReductions (Range);
@@ -8447,9 +8446,6 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
84478446
84488447 auto *MiddleVPBB = Plan->getMiddleBlock ();
84498448 VPBasicBlock::iterator MBIP = MiddleVPBB->getFirstNonPhi ();
8450- // Mapping from VPValues in the initial plan to their widened VPValues. Needed
8451- // temporarily to update created block masks.
8452- DenseMap<VPValue *, VPValue *> Old2New;
84538449 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
84548450 // Convert input VPInstructions to widened recipes.
84558451 for (VPRecipeBase &R : make_early_inc_range (*VPBB)) {
@@ -8505,7 +8501,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
85058501 }
85068502 if (Recipe->getNumDefinedValues () == 1 ) {
85078503 SingleDef->replaceAllUsesWith (Recipe->getVPSingleValue ());
8508- Old2New[ SingleDef] = Recipe-> getVPSingleValue ();
8504+ SingleDef-> eraseFromParent ();
85098505 } else {
85108506 assert (Recipe->getNumDefinedValues () == 0 &&
85118507 " Unexpected multidef recipe" );
@@ -8514,14 +8510,6 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
85148510 }
85158511 }
85168512
8517- // replaceAllUsesWith above may invalidate the block masks. Update them here.
8518- // TODO: Include the masks as operands in the predicated VPlan directly
8519- // to remove the need to keep a map of masks beyond the predication
8520- // transform.
8521- RecipeBuilder.updateBlockMaskCache (Old2New);
8522- for (VPValue *Old : Old2New.keys ())
8523- Old->getDefiningRecipe ()->eraseFromParent ();
8524-
85258513 assert (isa<VPRegionBlock>(LoopRegion) &&
85268514 !LoopRegion->getEntryBasicBlock ()->empty () &&
85278515 " entry block must be set to a VPRegionBlock having a non-empty entry "
@@ -8541,6 +8529,11 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
85418529 // Adjust the recipes for any inloop reductions.
85428530 adjustRecipesForReductions (Plan, RecipeBuilder, Range.Start );
85438531
8532+ // Erase the block entry masks, since they're not used any longer, so that
8533+ // future transforms only deal with recipe VPUsers.
8534+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT))
8535+ VPBB->eraseEntryMask ();
8536+
85448537 // Apply mandatory transformation to handle FP maxnum/minnum reduction with
85458538 // NaNs if possible, bail out otherwise.
85468539 if (!VPlanTransforms::runPass (VPlanTransforms::handleMaxMinNumReductions,
@@ -8792,7 +8785,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
87928785
87938786 VPValue *CondOp = nullptr ;
87948787 if (CM.blockNeedsPredicationForAnyReason (CurrentLinkI->getParent ()))
8795- CondOp = RecipeBuilder. getBlockInMask ( CurrentLink->getParent ());
8788+ CondOp = CurrentLink->getParent ()-> getEntryMask ( );
87968789
87978790 auto *RedRecipe = new VPReductionRecipe (
87988791 Kind, FMFs, CurrentLinkI, PreviousLink, VecOp, CondOp,
@@ -8833,7 +8826,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
88338826 // different numbers of lanes. Partial reductions mask the input instead.
88348827 if (!PhiR->isInLoop () && CM.foldTailByMasking () &&
88358828 !isa<VPPartialReductionRecipe>(OrigExitingVPV)) {
8836- VPValue *Cond = RecipeBuilder. getBlockInMask ( PhiR->getParent ());
8829+ VPValue *Cond = PhiR->getParent ()-> getEntryMask ( );
88378830 std::optional<FastMathFlags> FMFs =
88388831 PhiTy->isFloatingPointTy ()
88398832 ? std::make_optional (RdxDesc.getFastMathFlags ())
0 commit comments