[llvm] [LV][EVL] Replace VPInstruction::Select with vp.merge for predicated div/rem (PR #154072)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 01:26:17 PDT 2025
================
@@ -2160,18 +2160,20 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
return new VPReductionEVLRecipe(*Red, EVL, NewMask);
})
.Case<VPInstruction>([&](VPInstruction *VPI) -> VPRecipeBase * {
- VPValue *LHS, *RHS;
+ VPValue *Cond, *LHS, *RHS;
// Transform select with a header mask condition
- // select(header_mask, LHS, RHS)
+ // select(mask_w/_header_mask, LHS, RHS)
// into vector predication merge.
- // vp.merge(all-true, LHS, RHS, EVL)
- if (!match(VPI, m_Select(m_Specific(HeaderMask), m_VPValue(LHS),
- m_VPValue(RHS))))
+ // vp.merge(mask_w/o_header_mask, LHS, RHS, EVL)
+ if (!match(VPI,
+ m_Select(m_VPValue(Cond), m_VPValue(LHS), m_VPValue(RHS))))
return nullptr;
- // Use all true as the condition because this transformation is
- // limited to selects whose condition is a header mask.
+
+ VPValue *NewMask = GetNewMask(Cond);
+ if (!NewMask)
+ NewMask = &AllOneMask;
----------------
lukel97 wrote:
It's not correct to transform a recipe with no header mask to a VP intrinsic with EVL, e.g. this will now transform
`select <all ones>, foo, bar -> vp.select <all ones>, foo, bar, EVL`
Which don't have the same semantics.
This is something the VPWidenLoadRecipe/VPWidenStoreRecipe/VPReductionRecipe recipes do today too, but I think we really need to fix this in #155394 first.
If we land #155394, then we rewrite the pattern as
```c++
if (!match(VPI,
m_Select(m_RemoveMask(HeaderMask, Mask), m_VPValue(LHS), m_VPValue(RHS))))
return nullptr;
```
Which will only transform selects that use the header mask, and should be correct
https://github.com/llvm/llvm-project/pull/154072
More information about the llvm-commits
mailing list