[llvm] [VPlan] Use VPlan operand order for VPBlendRecipes. (PR #139475)

via llvm-commits llvm-commits at lists.llvm.org
Tue May 13 06:09:21 PDT 2025


================
@@ -8538,36 +8538,30 @@ VPWidenIntOrFpInductionRecipe *VPRecipeBuilder::tryToOptimizeInductionTruncate(
   return nullptr;
 }
 
-VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi,
-                                           ArrayRef<VPValue *> Operands) {
-  unsigned NumIncoming = Phi->getNumIncomingValues();
+VPBlendRecipe *VPRecipeBuilder::tryToBlend(VPWidenPHIRecipe *PhiR) {
+  unsigned NumIncoming = PhiR->getNumIncoming();
 
   // We know that all PHIs in non-header blocks are converted into selects, so
   // we don't have to worry about the insertion order and we can just use the
   // builder. At this point we generate the predication tree. There may be
   // duplications since this is a simple recursive scan, but future
   // optimizations will clean it up.
 
-  // Map incoming IR BasicBlocks to incoming VPValues, for lookup below.
-  // TODO: Add operands and masks in order from the VPlan predecessors.
-  DenseMap<BasicBlock *, VPValue *> VPIncomingValues;
-  for (const auto &[Idx, Pred] : enumerate(predecessors(Phi->getParent())))
----------------
ayalz wrote:

Would it make sense to set the operands according to order of predecessors instead? At-least temporarily, potentially initially, separating the reordering and associated test affects into a separate patch, leaving this one an NFC.

`PlainCFGBuilder::createVPInstructionsForVPBB()` sets the operands of VPWidenPHIRecipe according to the order of VPBB's predecessors, which should be consistent with that of underlying BB. It is the code below which traverses the operands of the original Phi according to their order. Would something like the following change here switch to predecessor order:
```
  for (const auto *Pred : predecessors(Phi->getParent())) {
    int Idx = Phi->getBasicBlockIndex(Pred);
    OperandsWithMask.push_back(Operands[Idx]);
    VPValue *EdgeMask = getEdgeMask(Pred, Phi->getParent());
    ...
  }
```
?

https://github.com/llvm/llvm-project/pull/139475


More information about the llvm-commits mailing list