[llvm] [LV] Optimize x && (x && y) -> x && y (PR #185806)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 15 19:25:35 PDT 2026


================
@@ -1374,6 +1374,12 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
     return Def->replaceAllUsesWith(
         Builder.createLogicalAnd(X, Builder.createOr(Y, Z)));
 
+  // x && (x && y) -> x && y
+  if (match(Def, m_LogicalAnd(m_VPValue(X),
+                              m_c_LogicalAnd(m_Deferred(X), m_VPValue(Y)))))
+    return Def->replaceAllUsesWith(
+        Def->getOperand(Def->getOperand(0) == X ? 1 : 0));
----------------
lukel97 wrote:

I think we need to create a new logical and if the second operand is (Y && X) because it always needs to be (X && Y), see https://alive2.llvm.org/ce/z/fyXFYd

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


More information about the llvm-commits mailing list