[llvm] 2a46e5d - [VPlan] Implement VPInterleaveRecipe::computeCost. (#106067)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 12:50:32 PDT 2024
Author: Florian Hahn
Date: 2024-10-15T20:50:28+01:00
New Revision: 2a46e5d03985620cbc55ed9839a263dc9646c240
URL: https://github.com/llvm/llvm-project/commit/2a46e5d03985620cbc55ed9839a263dc9646c240
DIFF: https://github.com/llvm/llvm-project/commit/2a46e5d03985620cbc55ed9839a263dc9646c240.diff
LOG: [VPlan] Implement VPInterleaveRecipe::computeCost. (#106067)
Implement computing costs for VPInterleaveRecipe.
PR: https://github.com/llvm/llvm-project/pull/106067
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 368d6e58a5578e..b3befce6c92c2c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2941,7 +2941,33 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent,
InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF,
VPCostContext &Ctx) const {
- return Ctx.getLegacyCost(IG->getInsertPos(), VF);
+ Instruction *I = getInsertPos();
+ Type *ValTy = Ctx.Types.inferScalarType(
+ getNumDefinedValues() > 0 ? getVPValue(0) : getStoredValues()[0]);
+ auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF));
+ unsigned AS = getLoadStoreAddressSpace(I);
+ enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+
+ unsigned InterleaveFactor = IG->getFactor();
+ auto *WideVecTy = VectorType::get(ValTy, VF * InterleaveFactor);
+
+ // Holds the indices of existing members in the interleaved group.
+ SmallVector<unsigned, 4> Indices;
+ for (unsigned IF = 0; IF < InterleaveFactor; IF++)
+ if (IG->getMember(IF))
+ Indices.push_back(IF);
+
+ // Calculate the cost of the whole interleaved group.
+ InstructionCost Cost = Ctx.TTI.getInterleavedMemoryOpCost(
+ I->getOpcode(), WideVecTy, IG->getFactor(), Indices, IG->getAlign(), AS,
+ CostKind, getMask(), NeedsMaskForGaps);
+
+ if (!IG->isReverse())
+ return Cost;
+
+ return Cost + IG->getNumMembers() *
+ Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Reverse,
+ VectorTy, std::nullopt, CostKind, 0);
}
void VPCanonicalIVPHIRecipe::execute(VPTransformState &State) {
More information about the llvm-commits
mailing list