[llvm] [VPlan] Add new VPInstruction ocpode for header mask. (PR #89603)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri May 3 06:19:43 PDT 2024


================
@@ -1203,52 +1164,32 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
   return LaneMaskPhi;
 }
 
-/// Collect all VPValues representing a header mask through the (ICMP_ULE,
-/// WideCanonicalIV, backedge-taken-count) pattern.
-/// TODO: Introduce explicit recipe for header-mask instead of searching
-/// for the header-mask pattern manually.
-static SmallVector<VPValue *> collectAllHeaderMasks(VPlan &Plan) {
-  SmallVector<VPValue *> WideCanonicalIVs;
-  auto *FoundWidenCanonicalIVUser =
-      find_if(Plan.getCanonicalIV()->users(),
-              [](VPUser *U) { return isa<VPWidenCanonicalIVRecipe>(U); });
-  assert(count_if(Plan.getCanonicalIV()->users(),
-                  [](VPUser *U) { return isa<VPWidenCanonicalIVRecipe>(U); }) <=
-             1 &&
-         "Must have at most one VPWideCanonicalIVRecipe");
-  if (FoundWidenCanonicalIVUser != Plan.getCanonicalIV()->users().end()) {
-    auto *WideCanonicalIV =
-        cast<VPWidenCanonicalIVRecipe>(*FoundWidenCanonicalIVUser);
-    WideCanonicalIVs.push_back(WideCanonicalIV);
-  }
-
-  // Also include VPWidenIntOrFpInductionRecipes that represent a widened
-  // version of the canonical induction.
+/// Return the header mask recipe of the VPlan, if there is one.
+static VPInstruction *getHeaderMask(VPlan &Plan) {
----------------
fhahn wrote:

> have Loop Region (1) provide a getHeaderMask() method which (always) returns a VPValue*

Left as is for now, as this would require to also look for ActiveLaneMask that replaces the HeaderMask VPInstruciton I think.

> (2) hold an abstract HeaderMask VPInstruction* field. The former retrieves the latter initially, later retrieves concrete header mask generating recipe.

Adding the this is a field adds extra burden on code that replaces/removes the header mask, as they would have to update the field. It might be better to manage the header mask (and/or canonical IV) via VPUser in VPRegionBlock; that way, RAUW of the header mask will also correctly update the reference in the region block. WDYT as follow-up?

That leaves the EVL case, where we don't replace the mask directly, but update users of the mask to use EVL, possibly removing the mask alltogether. This would require some special handling.

https://github.com/llvm/llvm-project/pull/89603


More information about the llvm-commits mailing list