[llvm] [VPlan] Implement VPInterleaveRecipe::computeCost. (PR #106067)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 01:18:48 PDT 2024
================
@@ -2627,6 +2625,37 @@ void VPInterleaveRecipe::execute(VPTransformState &State) {
}
}
+InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF,
+ VPCostContext &Ctx) const {
+ 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() *
----------------
fhahn wrote:
IIUC this extra computation could/should also be handled by `getInterleavedMemoryOpCost` above?
https://github.com/llvm/llvm-project/pull/106067
More information about the llvm-commits
mailing list