[llvm] [VPlan] Explicitly reassociate header mask in logical and (PR #180898)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 12 05:00:46 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;
+ SmallSetVector<VPUser *, 8> Worklist(HeaderMask->user_begin(),
+ HeaderMask->user_end());
+ while (!Worklist.empty()) {
----------------
lukel97 wrote:
By re-add do you mean a recipe is popped off the worklist and then added back? I think we only traverse users through logical-ands so there should never be a cycle, I don't think it can be added back.
I tried iterating with an index but it runs into problems, it looks like insert_range can invalidate the iterator? i.e. this ends up crashing trying to dereference what I presume is the end of an old iterator.
```c++
for (auto It = Worklist.begin(); It != Worklist.end(); ++It) {
VPUser *U = *It;
auto *R = dyn_cast<VPSingleDefRecipe>(U);
if (!R)
continue;
```
https://github.com/llvm/llvm-project/pull/180898
More information about the llvm-commits
mailing list