[llvm] [VPlan] Add new VPInstruction ocpode for header mask. (PR #89603)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 6 03:45:44 PDT 2024
================
@@ -1202,52 +1187,23 @@ 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.
- VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
- for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
- auto *WidenOriginalIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&Phi);
- if (WidenOriginalIV && WidenOriginalIV->isCanonical())
- WideCanonicalIVs.push_back(WidenOriginalIV);
- }
-
- // Walk users of wide canonical IVs and collect to all compares of the form
- // (ICMP_ULE, WideCanonicalIV, backedge-taken-count).
- SmallVector<VPValue *> HeaderMasks;
- VPValue *BTC = Plan.getOrCreateBackedgeTakenCount();
- for (auto *Wide : WideCanonicalIVs) {
- for (VPUser *U : SmallVector<VPUser *>(Wide->users())) {
- auto *HeaderMask = dyn_cast<VPInstruction>(U);
- if (!HeaderMask || HeaderMask->getOpcode() != Instruction::ICmp ||
- HeaderMask->getPredicate() != CmpInst::ICMP_ULE ||
- HeaderMask->getOperand(1) != BTC)
- continue;
-
- assert(HeaderMask->getOperand(0) == Wide &&
- "WidenCanonicalIV must be the first operand of the compare");
- HeaderMasks.push_back(HeaderMask);
+static VPValue *getOrCreateWideCanonicalIV(VPlan &Plan,
+ VPInstruction *HeaderMask) {
+ VPValue *Op = HeaderMask->getOperand(0);
+ if (isa<VPWidenIntOrFpInductionRecipe, VPScalarIVStepsRecipe>(Op))
+ return Op;
+ // Check if there is a wide canonical IV that can be re-used.
+ if (auto *CanIV = dyn_cast<VPCanonicalIVPHIRecipe>(Op)) {
----------------
ayalz wrote:
CanIV is now useless.
Is the check needed - does Op need to be a VPCanonicalIVPHIRecipe for the following search and replace to apply?
https://github.com/llvm/llvm-project/pull/89603
More information about the llvm-commits
mailing list