[llvm] [VPlan] Implement VPWidenCastRecipe::computeCost(). (NFCI) (PR #111339)
Elvis Wang via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 18:40:59 PDT 2024
================
@@ -1462,6 +1462,57 @@ 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())
+ 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, the context is the only user, which must be a
+ // VPWidenStoreRecipe, a VPInterleaveRecipe ,or a VPReplicateRecipe.
----------------
ElvisWang123 wrote:
Fixed, thanks.
https://github.com/llvm/llvm-project/pull/111339
More information about the llvm-commits
mailing list