[llvm] a477004 - [CostModel][X86] Remove getGSScalarCost and use getCommonMaskedMemoryOpCost directly
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun May 12 07:24:30 PDT 2024
Author: Simon Pilgrim
Date: 2024-05-12T15:21:08+01:00
New Revision: a477004d822d02290f9d388aa22a42490fd8180d
URL: https://github.com/llvm/llvm-project/commit/a477004d822d02290f9d388aa22a42490fd8180d
DIFF: https://github.com/llvm/llvm-project/commit/a477004d822d02290f9d388aa22a42490fd8180d.diff
LOG: [CostModel][X86] Remove getGSScalarCost and use getCommonMaskedMemoryOpCost directly
The generic getCommonMaskedMemoryOpCost now gives the same cost estimates for scalarized gather/scatter.
Added:
Modified:
llvm/lib/Target/X86/X86TargetTransformInfo.cpp
llvm/lib/Target/X86/X86TargetTransformInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
index ebcc11533add4..95cd35ac694b0 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -5841,59 +5841,12 @@ InstructionCost X86TTIImpl::getGSVectorCost(unsigned Opcode,
CostKind);
}
-/// Return the cost of full scalarization of gather / scatter operation.
-///
-/// Opcode - Load or Store instruction.
-/// SrcVTy - The type of the data vector that should be gathered or scattered.
-/// VariableMask - The mask is non-constant at compile time.
-/// Alignment - Alignment for one element.
-/// AddressSpace - pointer[s] address space.
-/// TODO: Remove this and use getCommonMaskedMemoryOpCost directly.
-InstructionCost X86TTIImpl::getGSScalarCost(unsigned Opcode,
- TTI::TargetCostKind CostKind,
- Type *SrcVTy, bool VariableMask,
- Align Alignment,
- unsigned AddressSpace) {
- Type *ScalarTy = SrcVTy->getScalarType();
- unsigned VF = cast<FixedVectorType>(SrcVTy)->getNumElements();
- APInt DemandedElts = APInt::getAllOnes(VF);
-
- InstructionCost MaskUnpackCost = 0;
- if (VariableMask) {
- auto *MaskTy =
- FixedVectorType::get(Type::getInt1Ty(SrcVTy->getContext()), VF);
- MaskUnpackCost = getScalarizationOverhead(
- MaskTy, DemandedElts, /*Insert=*/false, /*Extract=*/true, CostKind);
- InstructionCost BranchCost = getCFInstrCost(Instruction::Br, CostKind);
- MaskUnpackCost += VF * BranchCost;
- }
-
- InstructionCost AddressUnpackCost = getScalarizationOverhead(
- FixedVectorType::get(PointerType::getUnqual(ScalarTy->getContext()), VF),
- DemandedElts, /*Insert=*/false, /*Extract=*/true, CostKind);
-
- // The cost of the scalar loads/stores.
- InstructionCost MemoryOpCost =
- VF * getMemoryOpCost(Opcode, ScalarTy, MaybeAlign(Alignment),
- AddressSpace, CostKind);
-
- // The cost of forming the vector from loaded scalars/
- // scalarizing the vector to perform scalar stores.
- InstructionCost InsertExtractCost = getScalarizationOverhead(
- cast<FixedVectorType>(SrcVTy), DemandedElts,
- /*Insert=*/Opcode == Instruction::Load,
- /*Extract=*/Opcode == Instruction::Store, CostKind);
-
- return AddressUnpackCost + MemoryOpCost + MaskUnpackCost + InsertExtractCost;
-}
-
/// Calculate the cost of Gather / Scatter operation
InstructionCost X86TTIImpl::getGatherScatterOpCost(
unsigned Opcode, Type *SrcVTy, const Value *Ptr, bool VariableMask,
Align Alignment, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr) {
- if (CostKind != TTI::TCK_RecipThroughput &&
- ((Opcode == Instruction::Load &&
+ if (((Opcode == Instruction::Load &&
(!isLegalMaskedGather(SrcVTy, Align(Alignment)) ||
forceScalarizeMaskedGather(cast<VectorType>(SrcVTy),
Align(Alignment)))) ||
@@ -5911,18 +5864,6 @@ InstructionCost X86TTIImpl::getGatherScatterOpCost(
cast<VectorType>(Ptr->getType())->getElementType());
assert(PtrTy && "Unexpected type for Ptr argument");
unsigned AddressSpace = PtrTy->getAddressSpace();
-
- if ((Opcode == Instruction::Load &&
- (!isLegalMaskedGather(SrcVTy, Align(Alignment)) ||
- forceScalarizeMaskedGather(cast<VectorType>(SrcVTy),
- Align(Alignment)))) ||
- (Opcode == Instruction::Store &&
- (!isLegalMaskedScatter(SrcVTy, Align(Alignment)) ||
- forceScalarizeMaskedScatter(cast<VectorType>(SrcVTy),
- Align(Alignment)))))
- return getGSScalarCost(Opcode, CostKind, SrcVTy, VariableMask, Alignment,
- AddressSpace);
-
return getGSVectorCost(Opcode, CostKind, SrcVTy, Ptr, Alignment,
AddressSpace);
}
diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.h b/llvm/lib/Target/X86/X86TargetTransformInfo.h
index d720cc136b8ae..e14dc9fc09051 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.h
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.h
@@ -295,9 +295,6 @@ class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
private:
bool supportsGather() const;
- InstructionCost getGSScalarCost(unsigned Opcode, TTI::TargetCostKind CostKind,
- Type *DataTy, bool VariableMask,
- Align Alignment, unsigned AddressSpace);
InstructionCost getGSVectorCost(unsigned Opcode, TTI::TargetCostKind CostKind,
Type *DataTy, const Value *Ptr,
Align Alignment, unsigned AddressSpace);
More information about the llvm-commits
mailing list