@@ -7898,6 +7898,18 @@ void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
7898
7898
}
7899
7899
}
7900
7900
7901
+ iterator_range<mapped_iterator<Use *, std::function<VPValue *(Value *)>>>
7902
+ VPRecipeBuilder::mapToVPValues (User::op_range Operands) {
7903
+ std::function<VPValue *(Value *)> Fn = [this ](Value *Op) {
7904
+ if (auto *I = dyn_cast<Instruction>(Op)) {
7905
+ if (auto *R = Ingredient2Recipe.lookup (I))
7906
+ return R->getVPSingleValue ();
7907
+ }
7908
+ return Plan.getVPValueOrAddLiveIn (Op);
7909
+ };
7910
+ return map_range (Operands, Fn);
7911
+ }
7912
+
7901
7913
VPValue *VPRecipeBuilder::createEdgeMask (BasicBlock *Src, BasicBlock *Dst) {
7902
7914
assert (is_contained (predecessors (Dst), Src) && " Invalid edge" );
7903
7915
@@ -7922,7 +7934,7 @@ VPValue *VPRecipeBuilder::createEdgeMask(BasicBlock *Src, BasicBlock *Dst) {
7922
7934
if (OrigLoop->isLoopExiting (Src))
7923
7935
return EdgeMaskCache[Edge] = SrcMask;
7924
7936
7925
- VPValue *EdgeMask = Plan. getVPValueOrAddLiveIn (BI->getCondition ());
7937
+ VPValue *EdgeMask = getVPValueOrAddLiveIn (BI->getCondition (), Plan );
7926
7938
assert (EdgeMask && " No Edge Mask found for condition" );
7927
7939
7928
7940
if (BI->getSuccessor (0 ) != Dst)
@@ -8383,7 +8395,7 @@ VPReplicateRecipe *VPRecipeBuilder::handleReplication(Instruction *I,
8383
8395
BlockInMask = getBlockInMask (I->getParent ());
8384
8396
}
8385
8397
8386
- auto *Recipe = new VPReplicateRecipe (I, Plan. mapToVPValues (I->operands ()),
8398
+ auto *Recipe = new VPReplicateRecipe (I, mapToVPValues (I->operands ()),
8387
8399
IsUniform, BlockInMask);
8388
8400
return Recipe;
8389
8401
}
@@ -8399,10 +8411,6 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
8399
8411
if (Phi->getParent () != OrigLoop->getHeader ())
8400
8412
return tryToBlend (Phi, Operands);
8401
8413
8402
- // Always record recipes for header phis. Later first-order recurrence phis
8403
- // can have earlier phis as incoming values.
8404
- recordRecipeOf (Phi);
8405
-
8406
8414
if ((Recipe = tryToOptimizeInductionPHI (Phi, Operands, Range)))
8407
8415
return Recipe;
8408
8416
@@ -8427,14 +8435,6 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
8427
8435
PhiRecipe = new VPFirstOrderRecurrencePHIRecipe (Phi, *StartV);
8428
8436
}
8429
8437
8430
- // Record the incoming value from the backedge, so we can add the incoming
8431
- // value from the backedge after all recipes have been created.
8432
- auto *Inc = cast<Instruction>(
8433
- Phi->getIncomingValueForBlock (OrigLoop->getLoopLatch ()));
8434
- auto RecipeIter = Ingredient2Recipe.find (Inc);
8435
- if (RecipeIter == Ingredient2Recipe.end ())
8436
- recordRecipeOf (Inc);
8437
-
8438
8438
PhisToFix.push_back (PhiRecipe);
8439
8439
return PhiRecipe;
8440
8440
}
@@ -8522,7 +8522,7 @@ static void addCanonicalIVRecipes(VPlan &Plan, Type *IdxTy, bool HasNUW,
8522
8522
// Add exit values to \p Plan. VPLiveOuts are added for each LCSSA phi in the
8523
8523
// original exit block.
8524
8524
static void addUsersInExitBlock (VPBasicBlock *HeaderVPBB, Loop *OrigLoop,
8525
- VPlan &Plan) {
8525
+ VPRecipeBuilder &Builder, VPlan &Plan) {
8526
8526
BasicBlock *ExitBB = OrigLoop->getUniqueExitBlock ();
8527
8527
BasicBlock *ExitingBB = OrigLoop->getExitingBlock ();
8528
8528
// Only handle single-exit loops with unique exit blocks for now.
@@ -8533,7 +8533,7 @@ static void addUsersInExitBlock(VPBasicBlock *HeaderVPBB, Loop *OrigLoop,
8533
8533
for (PHINode &ExitPhi : ExitBB->phis ()) {
8534
8534
Value *IncomingValue =
8535
8535
ExitPhi.getIncomingValueForBlock (ExitingBB);
8536
- VPValue *V = Plan .getVPValueOrAddLiveIn (IncomingValue);
8536
+ VPValue *V = Builder .getVPValueOrAddLiveIn (IncomingValue, Plan );
8537
8537
Plan.addLiveOut (&ExitPhi, V);
8538
8538
}
8539
8539
}
@@ -8603,9 +8603,6 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
8603
8603
if (!getDecisionAndClampRange (applyIG, Range))
8604
8604
continue ;
8605
8605
InterleaveGroups.insert (IG);
8606
- for (unsigned i = 0 ; i < IG->getFactor (); i++)
8607
- if (Instruction *Member = IG->getMember (i))
8608
- RecipeBuilder.recordRecipeOf (Member);
8609
8606
};
8610
8607
8611
8608
// ---------------------------------------------------------------------------
@@ -8647,7 +8644,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
8647
8644
Operands.push_back (Plan->getVPValueOrAddLiveIn (
8648
8645
Phi->getIncomingValueForBlock (OrigLoop->getLoopPreheader ())));
8649
8646
} else {
8650
- auto OpRange = Plan-> mapToVPValues (Instr->operands ());
8647
+ auto OpRange = RecipeBuilder. mapToVPValues (Instr->operands ());
8651
8648
Operands = {OpRange.begin (), OpRange.end ()};
8652
8649
}
8653
8650
@@ -8662,10 +8659,6 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
8662
8659
RecipeBuilder.tryToCreateWidenRecipe (Instr, Operands, Range, VPBB);
8663
8660
if (!Recipe)
8664
8661
Recipe = RecipeBuilder.handleReplication (Instr, Range);
8665
- for (auto *Def : Recipe->definedValues ()) {
8666
- auto *UV = Def->getUnderlyingValue ();
8667
- Plan->addVPValue (UV, Def);
8668
- }
8669
8662
8670
8663
RecipeBuilder.setRecipe (Instr, Recipe);
8671
8664
if (isa<VPHeaderPHIRecipe>(Recipe)) {
@@ -8697,7 +8690,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
8697
8690
// and there is nothing to fix from vector loop; phis should have incoming
8698
8691
// from scalar loop only.
8699
8692
} else
8700
- addUsersInExitBlock (HeaderVPBB, OrigLoop, *Plan);
8693
+ addUsersInExitBlock (HeaderVPBB, OrigLoop, RecipeBuilder, *Plan);
8701
8694
8702
8695
assert (isa<VPRegionBlock>(Plan->getVectorLoopRegion ()) &&
8703
8696
!Plan->getVectorLoopRegion ()->getEntryBasicBlock ()->empty () &&
@@ -8765,10 +8758,6 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
8765
8758
Plan->getVPValueOrAddLiveIn (StrideV)->replaceAllUsesWith (ConstVPV);
8766
8759
}
8767
8760
8768
- // From this point onwards, VPlan-to-VPlan transformations may change the plan
8769
- // in ways that accessing values using original IR values is incorrect.
8770
- Plan->disableValue2VPValue ();
8771
-
8772
8761
VPlanTransforms::dropPoisonGeneratingRecipes (*Plan, [this ](BasicBlock *BB) {
8773
8762
return Legal->blockNeedsPredication (BB);
8774
8763
});
0 commit comments