[llvm] [LV][EVL] Replace VPInstruction::Select with vp.merge for predicated div/rem (PR #154072)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 01:41:57 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;
----------------
Mel-Chen wrote:

Ah, this is indeed a bit problematic, though we probably won’t find such an example in practice (it might never occur, or it could just get replaced directly by the LHS). We do need to first ensure that the mask is formed from a logical-and tree including the header mask before deciding what the new mask should be. https://github.com/llvm/llvm-project/pull/155394 looks good, but I’d like to adjusting GetNewMask in this PR to see if we can achieve the same effect. https://github.com/llvm/llvm-project/pull/154072/commits/3060d05df4b0fffe74485a97f173bd195151e5c0

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


More information about the llvm-commits mailing list