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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 11 00:53:00 PDT 2026


================
@@ -1374,6 +1374,11 @@ 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(1));
----------------
lukel97 wrote:

Good point. I guess it holds for the other simplifications above because they're with a constant. I think we then need to make the m_c_LogicalAnd non-commutative too

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


More information about the llvm-commits mailing list