[llvm] [LV] Support EVL for partial reduction and VPExpressionRecipe. (PR #205741)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 23:06:35 PDT 2026


================
@@ -3149,6 +3157,28 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
                                            Mask ? Mask : Plan->getTrue(), &EVL},
                                           IntrR->getScalarType(), {}, {}, DL);
 
+  // Transforms the VPReductionRecipe inside the VPExpressionRecipe.
+  if (auto *Expr = dyn_cast<VPExpressionRecipe>(&CurRecipe))
+    if (match(Expr->getOperand(Expr->getNumOperands() - 1),
+              m_RemoveMask(HeaderMask, Mask))) {
+      // Decompose first and construct with VPReductionEVLRecipe later.
+      SmallVector<VPSingleDefRecipe *> ExpressionRecipes = Expr->decompose();
+      VPReductionRecipe *Red =
+          cast<VPReductionRecipe>(ExpressionRecipes.pop_back_val());
+
+      // Convert to VPReductionEVLRecipe.
+      auto *NewRed = new VPReductionEVLRecipe(
+          *Red, EVL, Mask ? Mask : Plan->getTrue(), Red->getDebugLoc());
+      NewRed->insertBefore(Expr);
+      ExpressionRecipes.push_back(NewRed);
+      auto *NewExpr =
+          new VPExpressionRecipe(Expr->getExpressionType(), ExpressionRecipes);
----------------
lukel97 wrote:

That's what the original version of this PR did but it meant we had to duplicate the clone code and expose EVL specific stuff in VPExpressionRecipe: https://github.com/ElvisWang123/llvm-project/commit/a3dd20740f5190d6c25db23bd97480b3c323f799


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


More information about the llvm-commits mailing list