@@ -8115,14 +8115,6 @@ void EpilogueVectorizerEpilogueLoop::printDebugTracesAtEnd() {
81158115 });
81168116}
81178117
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-
81268118void VPRecipeBuilder::createSwitchEdgeMasks (SwitchInst *SI) {
81278119 BasicBlock *Src = SI->getParent ();
81288120 assert (!OrigLoop->isLoopExiting (Src) &&
@@ -8454,12 +8446,18 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi,
84548446 // builder. At this point we generate the predication tree. There may be
84558447 // duplications since this is a simple recursive scan, but future
84568448 // optimizations will clean it up.
8457- SmallVector<VPValue *, 2 > OperandsWithMask;
84588449
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;
84598457 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 ());
84638461 if (!EdgeMask) {
84648462 assert (In == 0 && " Both null and non-null edge masks found" );
84658463 assert (all_equal (Operands) &&
@@ -9449,16 +9447,6 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
94499447 // VPlan.
94509448 Instruction *Instr = cast<Instruction>(UnderlyingValue);
94519449 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- }
94629450
94639451 // The stores with invariant address inside the loop will be deleted, and
94649452 // in the exit block, a uniform store recipe will be created for the final
@@ -9468,15 +9456,15 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
94689456 Legal->isInvariantAddressOfReduction (SI->getPointerOperand ())) {
94699457 // Only create recipe for the final invariant store of the reduction.
94709458 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 */ );
94749461 Recipe->insertBefore (*MiddleVPBB, MBIP);
94759462 }
94769463 R.eraseFromParent ();
94779464 continue ;
94789465 }
94799466
9467+ SmallVector<VPValue *, 4 > Operands (R.operands ());
94809468 VPRecipeBase *Recipe =
94819469 RecipeBuilder.tryToCreateWidenRecipe (Instr, Operands, Range);
94829470 if (!Recipe)
0 commit comments