[llvm] [VPlan] Reassociate (x & y) & z -> x & (y & z) (PR #155383)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 03:56:17 PDT 2025


================
@@ -1119,6 +1119,15 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
     return;
   }
 
+  // Reassociate (x && y) && z -> x && (y && z) if x has multiple users. With
+  // tail folding it is likely that x is a header mask and can be simplified
+  // further.
+  if (match(Def, m_LogicalAnd(m_LogicalAnd(m_VPValue(X), m_VPValue(Y)),
+                              m_VPValue(Z))) &&
+      X->hasMoreThanOneUniqueUser())
+    return Def->replaceAllUsesWith(
+        Builder.createLogicalAnd(X, Builder.createLogicalAnd(X, Y)));
----------------
fhahn wrote:

Should this be 
```suggestion
        Builder.createLogicalAnd(X, Builder.createLogicalAnd(Y, Z)));
```

?

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


More information about the llvm-commits mailing list