[llvm] [VPlan] Simplify commutative logical ops (PR #156345)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 1 09:20:26 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_c_LogicalAnd(m_VPValue(X), m_False())))
+ return Def->replaceAllUsesWith(Def->getOperand(Def->getOperand(0) == X));
+
+ // x || true -> true
+ if (match(Def, m_c_LogicalOr(m_VPValue(X), m_True())))
+ return Def->replaceAllUsesWith(Def->getOperand(Def->getOperand(0) == X));
----------------
artagnon wrote:
I'm not 100% sure what's going on, but it's always the second operand of a logical-and is always the constant, for instance: I'm not sure if this is the case by construction, and I'm unable to craft a test where this is otherwise the case. As far as this hunk is concerned, replace m_c_Logical(And|Or) with a plan m_Logical(And|Or) has no effect, so the commutative part isn't exercised: I just used it in this hunk because it seems obvious that we want to match-commutative in this instance.
On second thought, I will revert the commutative changes, and simply extend simplifyRecipe in this patch?
https://github.com/llvm/llvm-project/pull/156345
More information about the llvm-commits
mailing list