@@ -2941,7 +2941,33 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent,
2941
2941
2942
2942
InstructionCost VPInterleaveRecipe::computeCost (ElementCount VF,
2943
2943
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 );
2945
2971
}
2946
2972
2947
2973
void VPCanonicalIVPHIRecipe::execute (VPTransformState &State) {
0 commit comments