@@ -1628,8 +1628,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
16281628 if (UseMaskForCond || UseMaskForGaps) {
16291629 unsigned IID = Opcode == Instruction::Load ? Intrinsic::masked_load
16301630 : Intrinsic::masked_store;
1631- Cost = thisT ()->getMaskedMemoryOpCost (
1632- {IID, VecTy, Alignment, AddressSpace}, CostKind);
1631+ Cost = thisT ()->getMemIntrinsicInstrCost (
1632+ MemIntrinsicCostAttributes (IID, VecTy, Alignment, AddressSpace),
1633+ CostKind);
16331634 } else
16341635 Cost = thisT ()->getMemoryOpCost (Opcode, VecTy, Alignment, AddressSpace,
16351636 CostKind);
@@ -1829,9 +1830,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
18291830 if (auto *VPI = dyn_cast_or_null<VPIntrinsic>(ICA.getInst ()))
18301831 Alignment = VPI->getPointerAlignment ().valueOrOne ();
18311832 bool VarMask = isa<Constant>(ICA.getArgs ()[2 ]);
1832- return thisT ()->getGatherScatterOpCost (
1833- Instruction::Store, ICA.getArgTypes ()[0 ], ICA.getArgs ()[1 ], VarMask,
1834- Alignment, CostKind, nullptr );
1833+ return thisT ()->getMemIntrinsicInstrCost (
1834+ MemIntrinsicCostAttributes (Intrinsic::vp_scatter,
1835+ ICA.getArgTypes ()[0 ], ICA.getArgs ()[1 ],
1836+ VarMask, Alignment, nullptr ),
1837+ CostKind);
18351838 }
18361839 if (ICA.getID () == Intrinsic::vp_gather) {
18371840 if (ICA.isTypeBasedOnly ()) {
@@ -1845,9 +1848,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
18451848 if (auto *VPI = dyn_cast_or_null<VPIntrinsic>(ICA.getInst ()))
18461849 Alignment = VPI->getPointerAlignment ().valueOrOne ();
18471850 bool VarMask = isa<Constant>(ICA.getArgs ()[1 ]);
1848- return thisT ()->getGatherScatterOpCost (
1849- Instruction::Load, ICA.getReturnType (), ICA.getArgs ()[0 ], VarMask,
1850- Alignment, CostKind, nullptr );
1851+ return thisT ()->getMemIntrinsicInstrCost (
1852+ MemIntrinsicCostAttributes (Intrinsic::vp_gather,
1853+ ICA.getReturnType (), ICA.getArgs ()[0 ],
1854+ VarMask, Alignment, nullptr ),
1855+ CostKind);
18511856 }
18521857
18531858 if (ICA.getID () == Intrinsic::vp_select ||
@@ -1952,30 +1957,34 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
19521957 const Value *Mask = Args[2 ];
19531958 bool VarMask = !isa<Constant>(Mask);
19541959 Align Alignment = I->getParamAlign (1 ).valueOrOne ();
1955- return thisT ()->getGatherScatterOpCost (Instruction::Store,
1956- ICA.getArgTypes ()[0 ], Args[1 ],
1957- VarMask, Alignment, CostKind, I);
1960+ return thisT ()->getMemIntrinsicInstrCost (
1961+ MemIntrinsicCostAttributes (Intrinsic::masked_scatter,
1962+ ICA.getArgTypes ()[0 ], Args[1 ], VarMask,
1963+ Alignment, I),
1964+ CostKind);
19581965 }
19591966 case Intrinsic::masked_gather: {
19601967 const Value *Mask = Args[1 ];
19611968 bool VarMask = !isa<Constant>(Mask);
19621969 Align Alignment = I->getParamAlign (0 ).valueOrOne ();
1963- return thisT ()->getGatherScatterOpCost (Instruction::Load, RetTy, Args[0 ],
1964- VarMask, Alignment, CostKind, I);
1970+ return thisT ()->getMemIntrinsicInstrCost (
1971+ MemIntrinsicCostAttributes (Intrinsic::masked_gather, RetTy, Args[0 ],
1972+ VarMask, Alignment, I),
1973+ CostKind);
19651974 }
19661975 case Intrinsic::masked_compressstore: {
19671976 const Value *Data = Args[0 ];
19681977 const Value *Mask = Args[2 ];
19691978 Align Alignment = I->getParamAlign (1 ).valueOrOne ();
1970- return thisT ()->getExpandCompressMemoryOpCost (
1979+ return thisT ()->getMemIntrinsicInstrCost (
19711980 MemIntrinsicCostAttributes (IID, Data->getType (), !isa<Constant>(Mask),
19721981 Alignment, I),
19731982 CostKind);
19741983 }
19751984 case Intrinsic::masked_expandload: {
19761985 const Value *Mask = Args[1 ];
19771986 Align Alignment = I->getParamAlign (0 ).valueOrOne ();
1978- return thisT ()->getExpandCompressMemoryOpCost (
1987+ return thisT ()->getMemIntrinsicInstrCost (
19791988 MemIntrinsicCostAttributes (IID, RetTy, !isa<Constant>(Mask),
19801989 Alignment, I),
19811990 CostKind);
@@ -1989,9 +1998,10 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
19891998 Type *EltTy = cast<VectorType>(Data->getType ())->getElementType ();
19901999 Align Alignment =
19912000 I->getParamAlign (1 ).value_or (thisT ()->DL .getABITypeAlign (EltTy));
1992- return thisT ()->getStridedMemoryOpCost (Instruction::Store,
1993- Data->getType (), Ptr, VarMask,
1994- Alignment, CostKind, I);
2001+ return thisT ()->getMemIntrinsicInstrCost (
2002+ MemIntrinsicCostAttributes (IID, Data->getType (), Ptr, VarMask,
2003+ Alignment, I),
2004+ CostKind);
19952005 }
19962006 case Intrinsic::experimental_vp_strided_load: {
19972007 const Value *Ptr = Args[0 ];
@@ -2001,8 +2011,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
20012011 Type *EltTy = cast<VectorType>(RetTy)->getElementType ();
20022012 Align Alignment =
20032013 I->getParamAlign (0 ).value_or (thisT ()->DL .getABITypeAlign (EltTy));
2004- return thisT ()->getStridedMemoryOpCost (Instruction::Load, RetTy, Ptr,
2005- VarMask, Alignment, CostKind, I);
2014+ return thisT ()->getMemIntrinsicInstrCost (
2015+ MemIntrinsicCostAttributes (IID, RetTy, Ptr, VarMask, Alignment, I),
2016+ CostKind);
20062017 }
20072018 case Intrinsic::stepvector: {
20082019 if (isa<ScalableVectorType>(RetTy))
@@ -2415,26 +2426,32 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
24152426 case Intrinsic::masked_store: {
24162427 Type *Ty = Tys[0 ];
24172428 Align TyAlign = thisT ()->DL .getABITypeAlign (Ty);
2418- return thisT ()->getMaskedMemoryOpCost ({IID, Ty, TyAlign, 0 }, CostKind);
2429+ return thisT ()->getMemIntrinsicInstrCost (
2430+ MemIntrinsicCostAttributes (IID, Ty, TyAlign, 0 ), CostKind);
24192431 }
24202432 case Intrinsic::masked_load: {
24212433 Type *Ty = RetTy;
24222434 Align TyAlign = thisT ()->DL .getABITypeAlign (Ty);
2423- return thisT ()->getMaskedMemoryOpCost ({IID, Ty, TyAlign, 0 }, CostKind);
2435+ return thisT ()->getMemIntrinsicInstrCost (
2436+ MemIntrinsicCostAttributes (IID, Ty, TyAlign, 0 ), CostKind);
24242437 }
24252438 case Intrinsic::experimental_vp_strided_store: {
24262439 auto *Ty = cast<VectorType>(ICA.getArgTypes ()[0 ]);
24272440 Align Alignment = thisT ()->DL .getABITypeAlign (Ty->getElementType ());
2428- return thisT ()->getStridedMemoryOpCost (
2429- Instruction::Store, Ty, /* Ptr=*/ nullptr , /* VariableMask=*/ true ,
2430- Alignment, CostKind, ICA.getInst ());
2441+ return thisT ()->getMemIntrinsicInstrCost (
2442+ MemIntrinsicCostAttributes (IID, Ty, /* Ptr=*/ nullptr ,
2443+ /* VariableMask=*/ true , Alignment,
2444+ ICA.getInst ()),
2445+ CostKind);
24312446 }
24322447 case Intrinsic::experimental_vp_strided_load: {
24332448 auto *Ty = cast<VectorType>(ICA.getReturnType ());
24342449 Align Alignment = thisT ()->DL .getABITypeAlign (Ty->getElementType ());
2435- return thisT ()->getStridedMemoryOpCost (
2436- Instruction::Load, Ty, /* Ptr=*/ nullptr , /* VariableMask=*/ true ,
2437- Alignment, CostKind, ICA.getInst ());
2450+ return thisT ()->getMemIntrinsicInstrCost (
2451+ MemIntrinsicCostAttributes (IID, Ty, /* Ptr=*/ nullptr ,
2452+ /* VariableMask=*/ true , Alignment,
2453+ ICA.getInst ()),
2454+ CostKind);
24382455 }
24392456 case Intrinsic::vector_reduce_add:
24402457 case Intrinsic::vector_reduce_mul:
@@ -3022,6 +3039,48 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
30223039 return SingleCallCost;
30233040 }
30243041
3042+ // / Get memory intrinsic cost based on arguments.
3043+ InstructionCost
3044+ getMemIntrinsicInstrCost (const MemIntrinsicCostAttributes &MICA,
3045+ TTI::TargetCostKind CostKind) const override {
3046+ unsigned Id = MICA.getID ();
3047+ Type *DataTy = MICA.getDataType ();
3048+ const Value *Ptr = MICA.getPointer ();
3049+ const Instruction *I = MICA.getInst ();
3050+ bool VariableMask = MICA.getVariableMask ();
3051+ Align Alignment = MICA.getAlignment ();
3052+
3053+ switch (Id) {
3054+ case Intrinsic::experimental_vp_strided_load:
3055+ case Intrinsic::experimental_vp_strided_store: {
3056+ unsigned Opcode = Id == Intrinsic::experimental_vp_strided_load
3057+ ? Instruction::Load
3058+ : Instruction::Store;
3059+ return thisT ()->getStridedMemoryOpCost (Opcode, DataTy, Ptr, VariableMask,
3060+ Alignment, CostKind, I);
3061+ }
3062+ case Intrinsic::masked_scatter:
3063+ case Intrinsic::masked_gather:
3064+ case Intrinsic::vp_scatter:
3065+ case Intrinsic::vp_gather: {
3066+ unsigned Opcode =
3067+ (Id == Intrinsic::masked_gather || Id == Intrinsic::vp_gather)
3068+ ? Instruction::Load
3069+ : Instruction::Store;
3070+ return thisT ()->getGatherScatterOpCost (Opcode, DataTy, Ptr, VariableMask,
3071+ Alignment, CostKind, I);
3072+ }
3073+ case Intrinsic::masked_load:
3074+ case Intrinsic::masked_store:
3075+ return thisT ()->getMaskedMemoryOpCost (MICA, CostKind);
3076+ case Intrinsic::masked_compressstore:
3077+ case Intrinsic::masked_expandload:
3078+ return thisT ()->getExpandCompressMemoryOpCost (MICA, CostKind);
3079+ default :
3080+ llvm_unreachable (" unexpected intrinsic" );
3081+ }
3082+ }
3083+
30253084 // / Compute a cost of the given call instruction.
30263085 // /
30273086 // / Compute the cost of calling function F with return type RetTy and
0 commit comments