[llvm] [LV] Directly emit predicated select for reduction in VPlan. (PR #201740)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 03:52:48 PDT 2026
================
@@ -3049,8 +3049,17 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
if (auto *Rdx = dyn_cast<VPReductionRecipe>(&CurRecipe))
if (Rdx->isConditional() &&
- match(Rdx->getCondOp(), m_RemoveMask(HeaderMask, Mask)))
+ match(Rdx->getCondOp(), m_RemoveMask(HeaderMask, Mask))) {
+ // Remove the predicated select since vp.reduce already contains mask and
+ // evl.
+ VPSingleDefRecipe *VecOp = cast<VPSingleDefRecipe>(Rdx->getVecOp());
+ assert(
+ !match(VecOp, m_Select(m_VPValue(), m_VPValue(), m_VPValue())) &&
+ "Inloop reduction should be predicated before folding tail by evl");
+ VecOp->replaceAllUsesWith(VecOp->getOperand(1));
+ VecOp->eraseFromParent();
return new VPReductionEVLRecipe(*Rdx, EVL, Mask);
+ }
----------------
Mel-Chen wrote:
Perhaps we can drop this transformation entirely. Instead, we can apply a simplification rule as a follow-up:
```
vector.reduce(ChainOp, Kind, vp.merge(cond, VecOp, Iden(Kind), evl))
-->
vp.reduce(ChainOp, Kind, VecOp, cond, evl)
```
A similar approach was taken in #199510.
https://github.com/llvm/llvm-project/pull/201740
More information about the llvm-commits
mailing list