[llvm] [VPlan] Explicitly reassociate header mask in logical and (PR #180898)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 12 08:39:07 PST 2026
================
@@ -1614,6 +1605,31 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan) {
}
}
+/// Reassociate (headermask && x) && y -> headermask && (x && y) to allow the
+/// header mask to be simplified further, e.g. in optimizeEVLMasks.
+static void reassociateHeaderMask(VPlan &Plan) {
+ VPValue *HeaderMask = vputils::findHeaderMask(Plan);
+ if (!HeaderMask)
+ return;
+ SmallVector<VPUser *> Worklist(HeaderMask->users());
+ while (!Worklist.empty()) {
+ auto *R = dyn_cast<VPSingleDefRecipe>(Worklist.pop_back_val());
+ if (!R)
+ continue;
+ VPValue *X, *Y;
+ if (match(R, m_LogicalAnd(m_Specific(HeaderMask), m_VPValue())))
+ Worklist.append(R->user_begin(), R->user_end());
+ else if (match(R, m_LogicalAnd(
+ m_LogicalAnd(m_Specific(HeaderMask), m_VPValue(X)),
+ m_VPValue(Y)))) {
+ VPBuilder Builder(R);
+ Worklist.append(R->user_begin(), R->user_end());
+ R->replaceAllUsesWith(
+ Builder.createLogicalAnd(HeaderMask, Builder.createLogicalAnd(X, Y)));
----------------
ayalz wrote:
Slightly more logical to first update all users of R and then append them to worklist?
```suggestion
R->replaceAllUsesWith(
Builder.createLogicalAnd(HeaderMask, Builder.createLogicalAnd(X, Y)));
Worklist.append(R->user_begin(), R->user_end());
```
https://github.com/llvm/llvm-project/pull/180898
More information about the llvm-commits
mailing list