Skip to content

Commit cacfa70

Browse files
committed
[TTI] Remove getMaskedMemoryOpCost from Analysis/TargetTransformInfo
1 parent 5dfe7e7 commit cacfa70

File tree

6 files changed

+58
-50
lines changed

6 files changed

+58
-50
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,11 +1554,6 @@ class TargetTransformInfo {
15541554
OperandValueInfo OpdInfo = {OK_AnyValue, OP_None},
15551555
const Instruction *I = nullptr) const;
15561556

1557-
/// \return The cost of masked Load and Store instructions.
1558-
LLVM_ABI InstructionCost getMaskedMemoryOpCost(
1559-
unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
1560-
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
1561-
15621557
/// \return The cost of Expand Load or Compress Store operation
15631558
/// \p Opcode - is a type of memory access Load or Store
15641559
/// \p Src - a vector type of the data to be loaded or stored

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,10 +1606,13 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
16061606

16071607
// Firstly, the cost of load/store operation.
16081608
InstructionCost Cost;
1609-
if (UseMaskForCond || UseMaskForGaps)
1610-
Cost = thisT()->getMaskedMemoryOpCost(Opcode, VecTy, Alignment,
1611-
AddressSpace, CostKind);
1612-
else
1609+
if (UseMaskForCond || UseMaskForGaps) {
1610+
unsigned IID = (Opcode == Instruction::Load) ? Intrinsic::masked_load
1611+
: Intrinsic::masked_store;
1612+
Cost = thisT()->getMemIntrinsicInstrCost(
1613+
IID, VecTy, /*Ptr*/ nullptr, /*VariableMask*/ false, Alignment,
1614+
CostKind, /*Instruction*/ nullptr);
1615+
} else
16131616
Cost = thisT()->getMemoryOpCost(Opcode, VecTy, Alignment, AddressSpace,
16141617
CostKind);
16151618

@@ -2408,14 +2411,16 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
24082411
case Intrinsic::masked_store: {
24092412
Type *Ty = Tys[0];
24102413
Align TyAlign = thisT()->DL.getABITypeAlign(Ty);
2411-
return thisT()->getMaskedMemoryOpCost(Instruction::Store, Ty, TyAlign, 0,
2412-
CostKind);
2414+
return thisT()->getMemIntrinsicInstrCost(
2415+
Intrinsic::masked_store, Ty,
2416+
/*Ptr*/ nullptr, /*VariableMask*/ false, TyAlign, CostKind, nullptr);
24132417
}
24142418
case Intrinsic::masked_load: {
24152419
Type *Ty = RetTy;
24162420
Align TyAlign = thisT()->DL.getABITypeAlign(Ty);
2417-
return thisT()->getMaskedMemoryOpCost(Instruction::Load, Ty, TyAlign, 0,
2418-
CostKind);
2421+
return thisT()->getMemIntrinsicInstrCost(
2422+
Intrinsic::masked_load, Ty,
2423+
/*Ptr*/ nullptr, /*VariableMask*/ false, TyAlign, CostKind, nullptr);
24192424
}
24202425
case Intrinsic::experimental_vp_strided_store: {
24212426
auto *Ty = cast<VectorType>(ICA.getArgTypes()[0]);
@@ -3043,6 +3048,14 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
30433048
return thisT()->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
30443049
Alignment, CostKind, I);
30453050
}
3051+
case Intrinsic::masked_load:
3052+
case Intrinsic::masked_store: {
3053+
unsigned Opcode = (Id == Intrinsic::masked_load) ? Instruction::Load
3054+
: Instruction::Store;
3055+
unsigned AS = Ptr ? Ptr->getType()->getPointerAddressSpace() : 0;
3056+
return thisT()->getMaskedMemoryOpCost(Opcode, DataTy, Alignment, AS,
3057+
CostKind);
3058+
}
30463059
default:
30473060
llvm_unreachable("unexpected intrinsic");
30483061
}

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,15 +1182,6 @@ InstructionCost TargetTransformInfo::getMemoryOpCost(
11821182
return Cost;
11831183
}
11841184

1185-
InstructionCost TargetTransformInfo::getMaskedMemoryOpCost(
1186-
unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
1187-
TTI::TargetCostKind CostKind) const {
1188-
InstructionCost Cost = TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment,
1189-
AddressSpace, CostKind);
1190-
assert(Cost >= 0 && "TTI should not produce negative costs!");
1191-
return Cost;
1192-
}
1193-
11941185
InstructionCost TargetTransformInfo::getExpandCompressMemoryOpCost(
11951186
unsigned Opcode, Type *DataTy, bool VariableMask, Align Alignment,
11961187
TTI::TargetCostKind CostKind, const Instruction *I) const {

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5197,8 +5197,11 @@ LoopVectorizationCostModel::getConsecutiveMemOpCost(Instruction *I,
51975197
const Align Alignment = getLoadStoreAlignment(I);
51985198
InstructionCost Cost = 0;
51995199
if (Legal->isMaskRequired(I)) {
5200-
Cost += TTI.getMaskedMemoryOpCost(I->getOpcode(), VectorTy, Alignment, AS,
5201-
CostKind);
5200+
unsigned IID = (I->getOpcode() == Instruction::Load)
5201+
? Intrinsic::masked_load
5202+
: Intrinsic::masked_store;
5203+
Cost += TTI.getMemIntrinsicInstrCost(
5204+
IID, VectorTy, Ptr, /*VariableMask*/ false, Alignment, CostKind);
52025205
} else {
52035206
TTI::OperandValueInfo OpInfo = TTI::getOperandInfo(I->getOperand(0));
52045207
Cost += TTI.getMemoryOpCost(I->getOpcode(), VectorTy, Alignment, AS,

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6848,9 +6848,9 @@ static bool isMaskedLoadCompress(
68486848
ScalarLoadsCost;
68496849
InstructionCost LoadCost = 0;
68506850
if (IsMasked) {
6851-
LoadCost =
6852-
TTI.getMaskedMemoryOpCost(Instruction::Load, LoadVecTy, CommonAlignment,
6853-
LI->getPointerAddressSpace(), CostKind);
6851+
LoadCost = TTI.getMemIntrinsicInstrCost(
6852+
Intrinsic::masked_load, LoadVecTy, LI->getPointerOperand(),
6853+
/*VariableMask*/ false, CommonAlignment, CostKind);
68546854
} else {
68556855
LoadCost =
68566856
TTI.getMemoryOpCost(Instruction::Load, LoadVecTy, CommonAlignment,
@@ -7249,12 +7249,13 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
72497249
VectorGEPCost;
72507250
break;
72517251
case LoadsState::CompressVectorize:
7252-
VecLdCost += TTI.getMaskedMemoryOpCost(
7253-
Instruction::Load, SubVecTy, CommonAlignment,
7254-
LI0->getPointerAddressSpace(), CostKind) +
7255-
VectorGEPCost +
7256-
::getShuffleCost(TTI, TTI::SK_PermuteSingleSrc, SubVecTy,
7257-
{}, CostKind);
7252+
VecLdCost +=
7253+
TTI.getMemIntrinsicInstrCost(
7254+
Intrinsic::masked_load, SubVecTy, LI0->getPointerOperand(),
7255+
/*VariableMask*/ false, CommonAlignment, CostKind) +
7256+
VectorGEPCost +
7257+
::getShuffleCost(TTI, TTI::SK_PermuteSingleSrc, SubVecTy, {},
7258+
CostKind);
72587259
break;
72597260
case LoadsState::ScatterVectorize:
72607261
VecLdCost +=
@@ -15044,9 +15045,9 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
1504415045
Instruction::Load, LoadVecTy, InterleaveFactor, {},
1504515046
CommonAlignment, LI0->getPointerAddressSpace(), CostKind);
1504615047
} else if (IsMasked) {
15047-
VecLdCost = TTI->getMaskedMemoryOpCost(
15048-
Instruction::Load, LoadVecTy, CommonAlignment,
15049-
LI0->getPointerAddressSpace(), CostKind);
15048+
VecLdCost = TTI->getMemIntrinsicInstrCost(
15049+
Intrinsic::masked_load, LoadVecTy, LI0->getPointerOperand(),
15050+
/*VariableMask*/ false, CommonAlignment, CostKind);
1505015051
// TODO: include this cost into CommonCost.
1505115052
VecLdCost += ::getShuffleCost(*TTI, TTI::SK_PermuteSingleSrc,
1505215053
LoadVecTy, CompressMask, CostKind);

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,8 +3570,11 @@ InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF,
35703570

35713571
InstructionCost Cost = 0;
35723572
if (IsMasked) {
3573-
Cost +=
3574-
Ctx.TTI.getMaskedMemoryOpCost(Opcode, Ty, Alignment, AS, Ctx.CostKind);
3573+
unsigned IID = isa<VPWidenLoadRecipe>(this) ? Intrinsic::masked_load
3574+
: Intrinsic::masked_store;
3575+
const Value *Ptr = getLoadStorePointerOperand(&Ingredient);
3576+
Cost += Ctx.TTI.getMemIntrinsicInstrCost(
3577+
IID, Ty, Ptr, /*VariableMask*/ false, Alignment, Ctx.CostKind);
35753578
} else {
35763579
TTI::OperandValueInfo OpInfo = Ctx.getOperandInfo(
35773580
isa<VPWidenLoadRecipe, VPWidenLoadEVLRecipe>(this) ? getOperand(0)
@@ -3681,16 +3684,17 @@ InstructionCost VPWidenLoadEVLRecipe::computeCost(ElementCount VF,
36813684
if (!Consecutive || IsMasked)
36823685
return VPWidenMemoryRecipe::computeCost(VF, Ctx);
36833686

3684-
// We need to use the getMaskedMemoryOpCost() instead of getMemoryOpCost()
3687+
// We need to use the getMemIntrinsicInstrCost() instead of getMemoryOpCost()
36853688
// here because the EVL recipes using EVL to replace the tail mask. But in the
36863689
// legacy model, it will always calculate the cost of mask.
3687-
// TODO: Using getMemoryOpCost() instead of getMaskedMemoryOpCost when we
3690+
// TODO: Using getMemoryOpCost() instead of getMemIntrinsicInstrCost when we
36883691
// don't need to compare to the legacy cost model.
36893692
Type *Ty = toVectorTy(getLoadStoreType(&Ingredient), VF);
3690-
unsigned AS = cast<PointerType>(Ctx.Types.inferScalarType(getAddr()))
3691-
->getAddressSpace();
3692-
InstructionCost Cost = Ctx.TTI.getMaskedMemoryOpCost(
3693-
Instruction::Load, Ty, Alignment, AS, Ctx.CostKind);
3693+
const Align Alignment = getLoadStoreAlignment(&Ingredient);
3694+
const Value *Ptr = getLoadStorePointerOperand(&Ingredient);
3695+
InstructionCost Cost = Ctx.TTI.getMemIntrinsicInstrCost(
3696+
Intrinsic::masked_load, Ty, Ptr, /*VariableMask*/ false, Alignment,
3697+
Ctx.CostKind);
36943698
if (!Reverse)
36953699
return Cost;
36963700

@@ -3790,16 +3794,17 @@ InstructionCost VPWidenStoreEVLRecipe::computeCost(ElementCount VF,
37903794
if (!Consecutive || IsMasked)
37913795
return VPWidenMemoryRecipe::computeCost(VF, Ctx);
37923796

3793-
// We need to use the getMaskedMemoryOpCost() instead of getMemoryOpCost()
3797+
// We need to use the getMemIntrinsicInstrCost() instead of getMemoryOpCost()
37943798
// here because the EVL recipes using EVL to replace the tail mask. But in the
37953799
// legacy model, it will always calculate the cost of mask.
3796-
// TODO: Using getMemoryOpCost() instead of getMaskedMemoryOpCost when we
3800+
// TODO: Using getMemoryOpCost() instead of getMemIntrinsicInstrCost when we
37973801
// don't need to compare to the legacy cost model.
37983802
Type *Ty = toVectorTy(getLoadStoreType(&Ingredient), VF);
3799-
unsigned AS = cast<PointerType>(Ctx.Types.inferScalarType(getAddr()))
3800-
->getAddressSpace();
3801-
InstructionCost Cost = Ctx.TTI.getMaskedMemoryOpCost(
3802-
Instruction::Store, Ty, Alignment, AS, Ctx.CostKind);
3803+
const Align Alignment = getLoadStoreAlignment(&Ingredient);
3804+
const Value *Ptr = getLoadStorePointerOperand(&Ingredient);
3805+
InstructionCost Cost = Ctx.TTI.getMemIntrinsicInstrCost(
3806+
Intrinsic::masked_store, Ty, Ptr, /*VariableMask*/ false, Alignment,
3807+
Ctx.CostKind);
38033808
if (!Reverse)
38043809
return Cost;
38053810

0 commit comments

Comments
 (0)