[llvm] [VPlan] Implement VPInterleaveRecipe::computeCost. (PR #106067)
Renato Golin via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 12:38:00 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() *
----------------
rengolin wrote:
This looks a bit hard-coded. It would be better to get the attribute from `IG` and pass it to `getShuffleCost`, but this can be done in a future PR.
https://github.com/llvm/llvm-project/pull/106067
More information about the llvm-commits
mailing list