-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[VPlan] Implement VPReductionRecipe::computeCost(). NFC #107790
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
Changes from 6 commits
324659a
91fcf39
4f2cc46
28b82ca
041f41b
7acd294
80faae5
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2071,6 +2071,40 @@ void VPReductionEVLRecipe::execute(VPTransformState &State) { | |||||
| State.set(this, NewRed, /*IsScalar*/ true); | ||||||
| } | ||||||
|
|
||||||
| InstructionCost VPReductionRecipe::computeCost(ElementCount VF, | ||||||
| VPCostContext &Ctx) const { | ||||||
| RecurKind RdxKind = RdxDesc.getRecurrenceKind(); | ||||||
| Type *ElementTy = Ctx.Types.inferScalarType(this); | ||||||
| auto *VectorTy = cast<VectorType>(ToVectorTy(ElementTy, VF)); | ||||||
|
Contributor
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. infer the type for the recipe instead and assert that the type matches
Contributor
Author
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. Sure, thanks. |
||||||
| TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; | ||||||
| unsigned Opcode = RdxDesc.getOpcode(); | ||||||
|
|
||||||
| // TODO: Support any-of and in-loop reductions. | ||||||
| assert( | ||||||
| (!RecurrenceDescriptor::isAnyOfRecurrenceKind(RdxKind) || | ||||||
| ForceTargetInstructionCost.getNumOccurrences() > 0) && | ||||||
| "Any-of reduction not implemented in VPlan-based cost model currently."); | ||||||
| assert( | ||||||
| (!cast<VPReductionPHIRecipe>(getOperand(0))->isInLoop() || | ||||||
| ForceTargetInstructionCost.getNumOccurrences() > 0) && | ||||||
| "In-loop reduction not implemented in VPlan-based cost model currently."); | ||||||
|
|
||||||
| assert(ElementTy->getTypeID() == RdxDesc.getRecurrenceType()->getTypeID() && | ||||||
| "Infered type and recurrence type mismatch."); | ||||||
|
||||||
| "Infered type and recurrence type mismatch."); | |
| "Inferred type and recurrence type mismatch."); |
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.
This computes the cost for non-in loop and non-any-of reductions, correct? Would be good to add an assert an explanation why (for those the cost needs to be pre-computed at the moment)
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.
Thanks, I will add an assertion to check it is not an any-of reduction.
I tried to compute the cost of in-loop reductions by the vplan-based cost model.
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.
It would probably be better to add support for in-loop reductions separately, as it adds extra complexity and may introduce new divergences
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.
Sure, I will open another PR to address in-loop reduction.