Skip to content

Commit a477004

Browse files
committed
[CostModel][X86] Remove getGSScalarCost and use getCommonMaskedMemoryOpCost directly
The generic getCommonMaskedMemoryOpCost now gives the same cost estimates for scalarized gather/scatter.
1 parent 1d6bf0c commit a477004

File tree

2 files changed

+1
-63
lines changed

2 files changed

+1
-63
lines changed

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5841,59 +5841,12 @@ InstructionCost X86TTIImpl::getGSVectorCost(unsigned Opcode,
58415841
CostKind);
58425842
}
58435843

5844-
/// Return the cost of full scalarization of gather / scatter operation.
5845-
///
5846-
/// Opcode - Load or Store instruction.
5847-
/// SrcVTy - The type of the data vector that should be gathered or scattered.
5848-
/// VariableMask - The mask is non-constant at compile time.
5849-
/// Alignment - Alignment for one element.
5850-
/// AddressSpace - pointer[s] address space.
5851-
/// TODO: Remove this and use getCommonMaskedMemoryOpCost directly.
5852-
InstructionCost X86TTIImpl::getGSScalarCost(unsigned Opcode,
5853-
TTI::TargetCostKind CostKind,
5854-
Type *SrcVTy, bool VariableMask,
5855-
Align Alignment,
5856-
unsigned AddressSpace) {
5857-
Type *ScalarTy = SrcVTy->getScalarType();
5858-
unsigned VF = cast<FixedVectorType>(SrcVTy)->getNumElements();
5859-
APInt DemandedElts = APInt::getAllOnes(VF);
5860-
5861-
InstructionCost MaskUnpackCost = 0;
5862-
if (VariableMask) {
5863-
auto *MaskTy =
5864-
FixedVectorType::get(Type::getInt1Ty(SrcVTy->getContext()), VF);
5865-
MaskUnpackCost = getScalarizationOverhead(
5866-
MaskTy, DemandedElts, /*Insert=*/false, /*Extract=*/true, CostKind);
5867-
InstructionCost BranchCost = getCFInstrCost(Instruction::Br, CostKind);
5868-
MaskUnpackCost += VF * BranchCost;
5869-
}
5870-
5871-
InstructionCost AddressUnpackCost = getScalarizationOverhead(
5872-
FixedVectorType::get(PointerType::getUnqual(ScalarTy->getContext()), VF),
5873-
DemandedElts, /*Insert=*/false, /*Extract=*/true, CostKind);
5874-
5875-
// The cost of the scalar loads/stores.
5876-
InstructionCost MemoryOpCost =
5877-
VF * getMemoryOpCost(Opcode, ScalarTy, MaybeAlign(Alignment),
5878-
AddressSpace, CostKind);
5879-
5880-
// The cost of forming the vector from loaded scalars/
5881-
// scalarizing the vector to perform scalar stores.
5882-
InstructionCost InsertExtractCost = getScalarizationOverhead(
5883-
cast<FixedVectorType>(SrcVTy), DemandedElts,
5884-
/*Insert=*/Opcode == Instruction::Load,
5885-
/*Extract=*/Opcode == Instruction::Store, CostKind);
5886-
5887-
return AddressUnpackCost + MemoryOpCost + MaskUnpackCost + InsertExtractCost;
5888-
}
5889-
58905844
/// Calculate the cost of Gather / Scatter operation
58915845
InstructionCost X86TTIImpl::getGatherScatterOpCost(
58925846
unsigned Opcode, Type *SrcVTy, const Value *Ptr, bool VariableMask,
58935847
Align Alignment, TTI::TargetCostKind CostKind,
58945848
const Instruction *I = nullptr) {
5895-
if (CostKind != TTI::TCK_RecipThroughput &&
5896-
((Opcode == Instruction::Load &&
5849+
if (((Opcode == Instruction::Load &&
58975850
(!isLegalMaskedGather(SrcVTy, Align(Alignment)) ||
58985851
forceScalarizeMaskedGather(cast<VectorType>(SrcVTy),
58995852
Align(Alignment)))) ||
@@ -5911,18 +5864,6 @@ InstructionCost X86TTIImpl::getGatherScatterOpCost(
59115864
cast<VectorType>(Ptr->getType())->getElementType());
59125865
assert(PtrTy && "Unexpected type for Ptr argument");
59135866
unsigned AddressSpace = PtrTy->getAddressSpace();
5914-
5915-
if ((Opcode == Instruction::Load &&
5916-
(!isLegalMaskedGather(SrcVTy, Align(Alignment)) ||
5917-
forceScalarizeMaskedGather(cast<VectorType>(SrcVTy),
5918-
Align(Alignment)))) ||
5919-
(Opcode == Instruction::Store &&
5920-
(!isLegalMaskedScatter(SrcVTy, Align(Alignment)) ||
5921-
forceScalarizeMaskedScatter(cast<VectorType>(SrcVTy),
5922-
Align(Alignment)))))
5923-
return getGSScalarCost(Opcode, CostKind, SrcVTy, VariableMask, Alignment,
5924-
AddressSpace);
5925-
59265867
return getGSVectorCost(Opcode, CostKind, SrcVTy, Ptr, Alignment,
59275868
AddressSpace);
59285869
}

llvm/lib/Target/X86/X86TargetTransformInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,6 @@ class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
295295

296296
private:
297297
bool supportsGather() const;
298-
InstructionCost getGSScalarCost(unsigned Opcode, TTI::TargetCostKind CostKind,
299-
Type *DataTy, bool VariableMask,
300-
Align Alignment, unsigned AddressSpace);
301298
InstructionCost getGSVectorCost(unsigned Opcode, TTI::TargetCostKind CostKind,
302299
Type *DataTy, const Value *Ptr,
303300
Align Alignment, unsigned AddressSpace);

0 commit comments

Comments
 (0)