[llvm] [LV] Support EVL for partial reduction and VPExpressionRecipe. (PR #205741)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 7 00:10:02 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:
I prefer calling decompose, since I think it's important to keep the EVL specific code in one place instead of spreading it across the loop vectorizer. It's also the easiest way to keep `ExpressionRecipes` internal, and I don't see any particular hazards to using decompose.
Would like to hear what others think
https://github.com/llvm/llvm-project/pull/205741
More information about the llvm-commits
mailing list