-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[VPlan] Implement VPWidenCastRecipe::computeCost(). (NFCI) #111339
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 all commits
8a8462e
b43e6f9
de00e4b
5eadd23
29c4d81
fe37f08
230a0d2
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 |
|---|---|---|
|
|
@@ -1462,6 +1462,55 @@ void VPWidenCastRecipe::execute(VPTransformState &State) { | |
| State.addMetadata(Cast, cast_or_null<Instruction>(getUnderlyingValue())); | ||
| } | ||
|
|
||
| InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF, | ||
| VPCostContext &Ctx) const { | ||
| // Computes the CastContextHint from a recipes that may access memory. | ||
| auto ComputeCCH = [&](const VPRecipeBase *R) -> TTI::CastContextHint { | ||
| if (VF.isScalar()) | ||
|
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. This seems to be missing handling of VPInterleaveRecipe and VPReplicateRecipe? And returning normal for live ins (the !Loop->contains() case in the legacy cost model)
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. Thanks for catching that. Handling VPInterleaveRecipe and VPReplicateRecipe in |
||
| return TTI::CastContextHint::Normal; | ||
| if (isa<VPInterleaveRecipe>(R)) | ||
| return TTI::CastContextHint::Interleave; | ||
| if (const auto *ReplicateRecipe = dyn_cast<VPReplicateRecipe>(R)) | ||
| return ReplicateRecipe->isPredicated() ? TTI::CastContextHint::Masked | ||
| : TTI::CastContextHint::Normal; | ||
| const auto *WidenMemoryRecipe = dyn_cast<VPWidenMemoryRecipe>(R); | ||
| if (WidenMemoryRecipe == nullptr) | ||
| return TTI::CastContextHint::None; | ||
| if (!WidenMemoryRecipe->isConsecutive()) | ||
| return TTI::CastContextHint::GatherScatter; | ||
| if (WidenMemoryRecipe->isReverse()) | ||
| return TTI::CastContextHint::Reversed; | ||
| if (WidenMemoryRecipe->isMasked()) | ||
| return TTI::CastContextHint::Masked; | ||
| return TTI::CastContextHint::Normal; | ||
| }; | ||
|
|
||
| VPValue *Operand = getOperand(0); | ||
| TTI::CastContextHint CCH = TTI::CastContextHint::None; | ||
| // For Trunc/FPTrunc, get the context from the only user. | ||
| if ((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) && | ||
| !hasMoreThanOneUniqueUser() && getNumUsers() > 0) { | ||
| if (auto *StoreRecipe = dyn_cast<VPRecipeBase>(*user_begin())) | ||
| CCH = ComputeCCH(StoreRecipe); | ||
| } | ||
| // For Z/Sext, get the context from the operand. | ||
| else if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt || | ||
| Opcode == Instruction::FPExt) { | ||
| if (Operand->isLiveIn()) | ||
| CCH = TTI::CastContextHint::Normal; | ||
| else if (Operand->getDefiningRecipe()) | ||
| CCH = ComputeCCH(Operand->getDefiningRecipe()); | ||
| } | ||
|
|
||
| auto *SrcTy = | ||
| cast<VectorType>(ToVectorTy(Ctx.Types.inferScalarType(Operand), VF)); | ||
| auto *DestTy = cast<VectorType>(ToVectorTy(getResultType(), VF)); | ||
| // Arm TTI will use the underlying instruction to determine the cost. | ||
| return Ctx.TTI.getCastInstrCost( | ||
| Opcode, DestTy, SrcTy, CCH, TTI::TCK_RecipThroughput, | ||
| dyn_cast_if_present<Instruction>(getUnderlyingValue())); | ||
| } | ||
|
|
||
| #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||
| void VPWidenCastRecipe::print(raw_ostream &O, const Twine &Indent, | ||
| VPSlotTracker &SlotTracker) const { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.