-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[AArch64][LV] Reduce cost of scaled reduction extends #134074
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 1 commit
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 | ||
---|---|---|---|---|
|
@@ -1796,6 +1796,11 @@ InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF, | |||
// For Z/Sext, get the context from the operand. | ||||
else if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt || | ||||
Opcode == Instruction::FPExt) { | ||||
// If the extend is performed as part of another operation, it can be | ||||
// considered 'free'. | ||||
const VPlan *Plan = getParent()->getPlan(); | ||||
if (Plan->isScaledReductionExtension(getUnderlyingInstr())) | ||||
return TargetTransformInfo::TCC_Free; | ||||
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. This is only free iff the target has an instruction that implements the partial reduction in a way that it folds in the extend. I think this warrants another This does mean widening the meaning of 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. There's a bit of a conflict there, though – the current code looks up the operand and calculates a CCH based on that, whereas this focuses on users. This would override the existing CCH... I guess we could do that if the current CCH is Normal or None, otherwise leave it as is? 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. Yes, the documentation for CastContextHint says:
The first sentence suggests adding a new hint would make sense for this case, and the second part suggests that the interpretation is currently specific to loads/stores. For partial reductions, we'd indeed look at the single use.
If I read the code correctly for the zext/sext case it can only be set to 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. Immediately below my change is the code to look up the CCH based on the operand. I was imagining overriding the CCH after that code and letting the existing 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. This doesn't sound like a job for CCH, as it cannot handle the mul. In the long run I would expect this to work like #113903, where there is one vplan recipe that gets the entire cost of the extending reduction added to it. And we happily leave the legacy cost model behind us. The mul should also be free, as in
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. If the extend is free then it should be modeled similar to other special reductions in #113903 as @davemgreen mentioned. Recipes should encapsulate all information required to compute their costs. Otherwise we may have to spread logic to detect those free extends to multiple places (e.g. register pressure computation). This should also make it easier to perform a specific TTI query, instead of encoding some target-dependent knowledge directly in ::computeCost |
||||
if (Operand->isLiveIn()) | ||||
CCH = TTI::CastContextHint::Normal; | ||||
else if (Operand->getDefiningRecipe()) | ||||
|
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.
Is it possible for the sext/zext to have multiple uses, i.e. one for the partial reduction and one used for something else? If so, then it won't be free. We might need to check that all uses are for partial reductions.
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.
In fact, can't you just look at uses of
this
recipe and if all uses are for the VPPartialReductionRecipe then mark as free? I just wonder if this avoids having to keep a pointer set.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.
We already do that, in
VPRecipeBuilder::collectScaledReductions
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.
OK, then I think it would be good to have an assertion here at least, just in case that changes in future.
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.
For our initial motivating use case (the AArch64 dot product instructions), there would be an extra recipe (a multiply) between the extends and the partial reduction. So we would need to look for uses of uses. I'm not sure if anyone has a case for more than one operation between the extends and the reduction, but I decided to keep it simple for now instead of walking the vplan.
If it's preferable to do the walk, then sure, I can convert it.
(I guess we could also make the multiply free, but so far that hasn't been an issue in using wider VFs)
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.
Done. Walking the plan would be needed for an assert anyway.