[llvm] [VPlan] Reassociate header masks (PR #155383)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 1 09:16:43 PDT 2025


================
@@ -1119,6 +1120,14 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
     return;
   }
 
+  // Reassociate the header mask so it has more opportunities to be simplified.
+  // (headermask && x) && y -> headermask && (x && y)
+  if (HeaderMask && match(Def, m_LogicalAnd(m_LogicalAnd(m_Specific(HeaderMask),
+                                                         m_VPValue(X)),
+                                            m_VPValue(Y))))
+    return Def->replaceAllUsesWith(
+        Builder.createLogicalAnd(HeaderMask, Builder.createLogicalAnd(X, Y)));
+
----------------
lukel97 wrote:

Thanks for pointing this out, this turned out to be a great idea. Generalizing it for all ands significantly improves mask codegen for RISC-V on llvm-test-suite. Pushed in 2cd0bb5

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


More information about the llvm-commits mailing list