@@ -2941,7 +2941,33 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent,
29412941
29422942InstructionCost 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
29472973void VPCanonicalIVPHIRecipe::execute (VPTransformState &State) {
0 commit comments