@@ -8115,14 +8115,6 @@ void EpilogueVectorizerEpilogueLoop::printDebugTracesAtEnd() {
8115
8115
});
8116
8116
}
8117
8117
8118
- iterator_range<mapped_iterator<Use *, std::function<VPValue *(Value *)>>>
8119
- VPRecipeBuilder::mapToVPValues (User::op_range Operands) {
8120
- std::function<VPValue *(Value *)> Fn = [this ](Value *Op) {
8121
- return getVPValueOrAddLiveIn (Op);
8122
- };
8123
- return map_range (Operands, Fn);
8124
- }
8125
-
8126
8118
void VPRecipeBuilder::createSwitchEdgeMasks (SwitchInst *SI) {
8127
8119
BasicBlock *Src = SI->getParent ();
8128
8120
assert (!OrigLoop->isLoopExiting (Src) &&
@@ -8454,12 +8446,18 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi,
8454
8446
// builder. At this point we generate the predication tree. There may be
8455
8447
// duplications since this is a simple recursive scan, but future
8456
8448
// optimizations will clean it up.
8457
- SmallVector<VPValue *, 2 > OperandsWithMask;
8458
8449
8450
+ // Map incoming IR BasicBlocks to incoming VPValues, for lookup below.
8451
+ // TODO: Add operands and masks in order from the VPlan predecessors.
8452
+ DenseMap<BasicBlock *, VPValue *> VPIncomingValues;
8453
+ for (const auto &[Idx, Pred] : enumerate(predecessors (Phi->getParent ())))
8454
+ VPIncomingValues[Pred] = Operands[Idx];
8455
+
8456
+ SmallVector<VPValue *, 2 > OperandsWithMask;
8459
8457
for (unsigned In = 0 ; In < NumIncoming; In++) {
8460
- OperandsWithMask. push_back (Operands[In] );
8461
- VPValue *EdgeMask =
8462
- getEdgeMask (Phi-> getIncomingBlock (In) , Phi->getParent ());
8458
+ BasicBlock *Pred = Phi-> getIncomingBlock (In );
8459
+ OperandsWithMask. push_back (VPIncomingValues. lookup (Pred));
8460
+ VPValue *EdgeMask = getEdgeMask (Pred , Phi->getParent ());
8463
8461
if (!EdgeMask) {
8464
8462
assert (In == 0 && " Both null and non-null edge masks found" );
8465
8463
assert (all_equal (Operands) &&
@@ -9449,16 +9447,6 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9449
9447
// VPlan.
9450
9448
Instruction *Instr = cast<Instruction>(UnderlyingValue);
9451
9449
Builder.setInsertPoint (SingleDef);
9452
- SmallVector<VPValue *, 4 > Operands;
9453
- auto *Phi = dyn_cast<PHINode>(Instr);
9454
- if (Phi && Phi->getParent () == HeaderBB) {
9455
- // The backedge value will be added in fixHeaderPhis later.
9456
- Operands.push_back (Plan->getOrAddLiveIn (
9457
- Phi->getIncomingValueForBlock (OrigLoop->getLoopPreheader ())));
9458
- } else {
9459
- auto OpRange = RecipeBuilder.mapToVPValues (Instr->operands ());
9460
- Operands = {OpRange.begin (), OpRange.end ()};
9461
- }
9462
9450
9463
9451
// The stores with invariant address inside the loop will be deleted, and
9464
9452
// in the exit block, a uniform store recipe will be created for the final
@@ -9468,15 +9456,15 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9468
9456
Legal->isInvariantAddressOfReduction (SI->getPointerOperand ())) {
9469
9457
// Only create recipe for the final invariant store of the reduction.
9470
9458
if (Legal->isInvariantStoreOfReduction (SI)) {
9471
- auto *Recipe = new VPReplicateRecipe (
9472
- SI, make_range (Operands.begin (), Operands.end ()),
9473
- true /* IsUniform */ );
9459
+ auto *Recipe =
9460
+ new VPReplicateRecipe (SI, R.operands (), true /* IsUniform */ );
9474
9461
Recipe->insertBefore (*MiddleVPBB, MBIP);
9475
9462
}
9476
9463
R.eraseFromParent ();
9477
9464
continue ;
9478
9465
}
9479
9466
9467
+ SmallVector<VPValue *, 4 > Operands (R.operands ());
9480
9468
VPRecipeBase *Recipe =
9481
9469
RecipeBuilder.tryToCreateWidenRecipe (Instr, Operands, Range);
9482
9470
if (!Recipe)
0 commit comments