[llvm] [VPlan] Simplify logical-op identities (PR #156345)

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


================
@@ -1107,6 +1092,26 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
     return Def->replaceAllUsesWith(
         Builder.createLogicalAnd(X, Builder.createOr(Y, Z)));
 
+  // OR x, 1 -> 1
+  if (match(Def, m_c_BinaryOr(m_VPValue(X), m_AllOnes())))
+    return Def->replaceAllUsesWith(Def->getOperand(Def->getOperand(0) == X));
+
+  // OR x, 0 -> x
+  if (match(Def, m_c_BinaryOr(m_VPValue(X), m_ZeroInt())))
+    return Def->replaceAllUsesWith(X);
+
+  // AND x, 0 -> 0
+  if (match(Def, m_c_BinaryAnd(m_VPValue(X), m_ZeroInt())))
+    return Def->replaceAllUsesWith(Def->getOperand(Def->getOperand(0) == X));
+
+  // x && false -> false
+  if (match(Def, m_LogicalAnd(m_VPValue(X), m_False())))
+    return Def->replaceAllUsesWith(Def->getOperand(Def->getOperand(0) == X));
----------------
lukel97 wrote:

Nit if it's not commutative anymore I think this can be
```suggestion
    return Def->replaceAllUsesWith(Def->getOperand(1));
```

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


More information about the llvm-commits mailing list