[llvm] [VPlan] Reassociate header masks and simplify (x && y) || (x && z) -> x && (y || z) (PR #155383)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 27 09:17:18 PDT 2025
================
@@ -1084,6 +1086,15 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
return;
}
+ // (x && y) || (x && z) -> x && (y || z)
+ if (match(Def, m_c_BinaryOr(m_LogicalAnd(m_VPValue(X), m_VPValue(Y)),
+ m_LogicalAnd(m_Deferred(X), m_VPValue(Z)))) &&
+ // Creating an extra recipe, so at least one arm needs to have one use.
+ (!Def->getOperand(0)->hasMoreThanOneUniqueUser() ||
+ !Def->getOperand(1)->hasMoreThanOneUniqueUser()))
----------------
lukel97 wrote:
If one of the arms has more than one use then it won't be dead after the transform.
Given this transform introduces 2 recipes, the replacement should be at most 2 recipes.
If both arms have more than one use then they'll still hang around, and we'll go from 3->4 recipes in total.
So the guard that at least one arm will be dead is a heuristic to avoid the above scenario. We do it in quite a few places in InstCombine and DAGCombine IIRC
https://github.com/llvm/llvm-project/pull/155383
More information about the llvm-commits
mailing list