-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[VPlan] Sink retrieving legacy costs to more specific computeCost impls. #109708
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
8117ba1
f409232
0bf2760
9f12dab
16ca2ca
f632630
c75d678
d32eb48
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 |
|---|---|---|
|
|
@@ -276,14 +276,6 @@ static Instruction *getInstructionForCost(const VPRecipeBase *R) { | |
| return dyn_cast_or_null<Instruction>(S->getUnderlyingValue()); | ||
|
||
| if (auto *IG = dyn_cast<VPInterleaveRecipe>(R)) | ||
| return IG->getInsertPos(); | ||
| // Currently the legacy cost model only calculates the instruction cost with | ||
| // underlying instruction. Removing the WidenMem here will prevent | ||
| // force-target-instruction-cost overwriting the cost of recipe with | ||
| // underlying instruction which is inconsistent with the legacy model. | ||
| // TODO: Remove WidenMem from this function when we don't need to compare to | ||
| // the legacy model. | ||
| if (auto *WidenMem = dyn_cast<VPWidenMemoryRecipe>(R)) | ||
| return &WidenMem->getIngredient(); | ||
|
Collaborator
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. Worth leaving a note, that even though widen loads and stores have an underlying instruction ("ingredient"), null is returned - in order to match legacy cost model behavior with force-target-instruction-cost? The instruction a recipe provides for cost affects both
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. Clarified the the comment about the return value for the function. Nullptr is returned if either the recipe doesn't have an underlying instruction or computeCost is implemented and there is no need for the underlying instruction (i.e. it should not be needed to be skipped)
Collaborator
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.
Regarding the "else" part of this "or" - not needing UI because recipe is not to be skipped is fine (if it's absence from SkipCostComputation it won't be skipped), but would UI still be needed in order to apply ForceTargetInstructionCost?
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. This has been reworked in the latest version. The function is gone and inline to |
||
| return nullptr; | ||
| } | ||
|
|
||
|
|
@@ -293,9 +285,13 @@ InstructionCost VPRecipeBase::cost(ElementCount VF, VPCostContext &Ctx) { | |
| return 0; | ||
|
||
|
|
||
| InstructionCost RecipeCost = computeCost(VF, Ctx); | ||
| if (UI && ForceTargetInstructionCost.getNumOccurrences() > 0 && | ||
| RecipeCost.isValid()) | ||
| if (ForceTargetInstructionCost.getNumOccurrences() > 0 && | ||
| (RecipeCost.isValid() && RecipeCost != InstructionCost::getMax())) | ||
| RecipeCost = InstructionCost(ForceTargetInstructionCost); | ||
| // Max cost is used as a sentinel value to detect recipes without underlying | ||
| // instructions for which no forced target instruction cost should be applied. | ||
|
||
| if (RecipeCost == InstructionCost::getMax()) | ||
|
||
| RecipeCost = 0; | ||
|
||
|
|
||
| LLVM_DEBUG({ | ||
| dbgs() << "Cost of " << RecipeCost << " for VF " << VF << ": "; | ||
|
|
@@ -315,7 +311,9 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF, | |
| // transform, avoid computing their cost multiple times for now. | ||
| Ctx.SkipCostComputation.insert(UI); | ||
| } | ||
| return UI ? Ctx.getLegacyCost(UI, VF) : 0; | ||
| // Max cost is used as a sentinel value to detect recipes without underlying | ||
| // instructions for which no forced target instruction cost should be applied. | ||
| return UI ? Ctx.getLegacyCost(UI, VF) : InstructionCost::getMax(); | ||
|
||
| } | ||
|
|
||
| FastMathFlags VPRecipeWithIRFlags::getFastMathFlags() const { | ||
|
|
||
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.
The underlying instruction can be passed as argument, except that this base implementation should be a default for all derived VPlan-based computations, where the latter should be independent on UI, if possible?
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.
Yes, also there are some computeCost implementation for recipes with underlying instruction, for which the default should not trigger. In particular, all recipes which currently have computeCost implemented in subclasses should be included with force-target-instruction-cost.
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.
Perhaps better to return no cost at all, as in optional, when cost should be ignored, rather than a max sentinel. The latter requires additional attention to remain unmodified, preventing (mistaken) updates.
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.
Change is not needed in latest version.