-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[VPlan] Add new VPInstruction ocpode for header mask. #89603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2630805
8ea7c45
354777e
5fed0d1
5324561
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1176,6 +1176,12 @@ class VPInstruction : public VPRecipeWithIRFlags { | |
BranchOnCount, | ||
BranchOnCond, | ||
ComputeReductionResult, | ||
// An abstract representation of the vector loops header mask, to be lowered | ||
// later depending on target preference. Relevant only when the header may | ||
// have a partial mask, i.e., when tail folding. A mask known to always be | ||
// full is represented by null, w/o a HeaderMask recipe. A header mask may | ||
// not be empty. | ||
HeaderMask, | ||
// Add an offset in bytes (second operand) to a base pointer (first | ||
// operand). Only generates scalar values (either for the first lane only or | ||
// for all lanes, depending on its uses). | ||
|
@@ -2688,14 +2694,13 @@ class VPEVLBasedIVPHIRecipe : public VPHeaderPHIRecipe { | |
/// A Recipe for widening the canonical induction variable of the vector loop. | ||
class VPWidenCanonicalIVRecipe : public VPSingleDefRecipe { | ||
public: | ||
VPWidenCanonicalIVRecipe(VPCanonicalIVPHIRecipe *CanonicalIV) | ||
: VPSingleDefRecipe(VPDef::VPWidenCanonicalIVSC, {CanonicalIV}) {} | ||
VPWidenCanonicalIVRecipe(VPValue *Start) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's still a [Scalar]CanonicalIV, right? |
||
: VPSingleDefRecipe(VPDef::VPWidenCanonicalIVSC, {Start}) {} | ||
|
||
~VPWidenCanonicalIVRecipe() override = default; | ||
|
||
VPWidenCanonicalIVRecipe *clone() override { | ||
return new VPWidenCanonicalIVRecipe( | ||
cast<VPCanonicalIVPHIRecipe>(getOperand(0))); | ||
return new VPWidenCanonicalIVRecipe(getOperand(0)); | ||
} | ||
|
||
VP_CLASSOF_IMPL(VPDef::VPWidenCanonicalIVSC) | ||
|
@@ -2710,12 +2715,6 @@ class VPWidenCanonicalIVRecipe : public VPSingleDefRecipe { | |
void print(raw_ostream &O, const Twine &Indent, | ||
VPSlotTracker &SlotTracker) const override; | ||
#endif | ||
|
||
/// Returns the scalar type of the induction. | ||
const Type *getScalarType() const { | ||
return cast<VPCanonicalIVPHIRecipe>(getOperand(0)->getDefiningRecipe()) | ||
->getScalarType(); | ||
} | ||
}; | ||
|
||
/// A recipe for converting the input value \p IV value to the corresponding | ||
|
@@ -3055,6 +3054,9 @@ class VPRegionBlock : public VPBlockBase { | |
/// Clone all blocks in the single-entry single-exit region of the block and | ||
/// their recipes without updating the operands of the cloned recipes. | ||
VPRegionBlock *clone() override; | ||
|
||
/// Return the header mask recipe of the VPlan, if there is one. | ||
VPInstruction *getHeaderMask(VPlan &Plan) const; | ||
}; | ||
|
||
/// VPlan models a candidate for vectorization, encoding various decisions take | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ bool VPRecipeBase::mayHaveSideEffects() const { | |
case VPInstruction::Not: | ||
case VPInstruction::CalculateTripCountMinusVF: | ||
case VPInstruction::CanonicalIVIncrementForPart: | ||
case VPInstruction::HeaderMask: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: would be good to list in lex order, so better placed before PtrAdd. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks! |
||
case VPInstruction::PtrAdd: | ||
return false; | ||
default: | ||
|
@@ -690,6 +691,9 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent, | |
case VPInstruction::ComputeReductionResult: | ||
O << "compute-reduction-result"; | ||
break; | ||
case VPInstruction::HeaderMask: | ||
O << "header-mask"; | ||
break; | ||
case VPInstruction::PtrAdd: | ||
O << "ptradd"; | ||
break; | ||
|
@@ -1897,22 +1901,21 @@ void VPExpandSCEVRecipe::print(raw_ostream &O, const Twine &Indent, | |
#endif | ||
|
||
void VPWidenCanonicalIVRecipe::execute(VPTransformState &State) { | ||
Value *CanonicalIV = State.get(getOperand(0), 0, /*IsScalar*/ true); | ||
Type *STy = CanonicalIV->getType(); | ||
Value *Start = State.get(getOperand(0), 0, /*IsScalar*/ true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Scalar]CanonicalIV? Admittedly used to build |
||
Type *STy = Start->getType(); | ||
IRBuilder<> Builder(State.CFG.PrevBB->getTerminator()); | ||
ElementCount VF = State.VF; | ||
Value *VStart = VF.isScalar() | ||
? CanonicalIV | ||
: Builder.CreateVectorSplat(VF, CanonicalIV, "broadcast"); | ||
Value *VStart = | ||
VF.isScalar() ? Start : Builder.CreateVectorSplat(VF, Start, "broadcast"); | ||
for (unsigned Part = 0, UF = State.UF; Part < UF; ++Part) { | ||
Value *VStep = createStepForVF(Builder, STy, VF, Part); | ||
if (VF.isVector()) { | ||
VStep = Builder.CreateVectorSplat(VF, VStep); | ||
VStep = | ||
Builder.CreateAdd(VStep, Builder.CreateStepVector(VStep->getType())); | ||
} | ||
Value *CanonicalVectorIV = Builder.CreateAdd(VStart, VStep, "vec.iv"); | ||
State.set(this, CanonicalVectorIV, Part); | ||
Value *Res = Builder.CreateAdd(VStart, VStep, "vec.iv"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Retain name - this still generates a canonical wide IV? |
||
State.set(this, Res, Part); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(TODO) The three passes that lower the header mask (addActiveLaneMask, addExplicitVectorLength, lowerRecipes) should arguably be applied together, depending on tail folding style, inside VPlanTransforms::optimize().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, the TODO above, thanks!