Skip to content

Commit 2a46e5d

Browse files
authored
[VPlan] Implement VPInterleaveRecipe::computeCost. (#106067)
Implement computing costs for VPInterleaveRecipe. PR: #106067
1 parent be0c67c commit 2a46e5d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,33 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent,
29412941

29422942
InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF,
29432943
VPCostContext &Ctx) const {
2944-
return Ctx.getLegacyCost(IG->getInsertPos(), VF);
2944+
Instruction *I = getInsertPos();
2945+
Type *ValTy = Ctx.Types.inferScalarType(
2946+
getNumDefinedValues() > 0 ? getVPValue(0) : getStoredValues()[0]);
2947+
auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF));
2948+
unsigned AS = getLoadStoreAddressSpace(I);
2949+
enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
2950+
2951+
unsigned InterleaveFactor = IG->getFactor();
2952+
auto *WideVecTy = VectorType::get(ValTy, VF * InterleaveFactor);
2953+
2954+
// Holds the indices of existing members in the interleaved group.
2955+
SmallVector<unsigned, 4> Indices;
2956+
for (unsigned IF = 0; IF < InterleaveFactor; IF++)
2957+
if (IG->getMember(IF))
2958+
Indices.push_back(IF);
2959+
2960+
// Calculate the cost of the whole interleaved group.
2961+
InstructionCost Cost = Ctx.TTI.getInterleavedMemoryOpCost(
2962+
I->getOpcode(), WideVecTy, IG->getFactor(), Indices, IG->getAlign(), AS,
2963+
CostKind, getMask(), NeedsMaskForGaps);
2964+
2965+
if (!IG->isReverse())
2966+
return Cost;
2967+
2968+
return Cost + IG->getNumMembers() *
2969+
Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Reverse,
2970+
VectorTy, std::nullopt, CostKind, 0);
29452971
}
29462972

29472973
void VPCanonicalIVPHIRecipe::execute(VPTransformState &State) {

0 commit comments

Comments
 (0)