[llvm] [VPlan] Simplify commutative logical ops (PR #156345)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 1 09:06:53 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));
----------------
fhahn wrote:
Could you not add additional tests for the new simplifications? Is there something that makes it inherently impossible to check them in isolation?
https://github.com/llvm/llvm-project/pull/156345
More information about the llvm-commits
mailing list