[llvm-branch-commits] [llvm] [AMDGPU] Price memory operations by the number of memory instructions (PR #233261)
Dmitry Sidorov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 19 03:16:06 PDT 2026
================
@@ -2115,22 +2115,89 @@ GCNTTIImpl::fpenvIEEEMode(const Instruction &I) const {
: KnownIEEEMode::On;
}
+static unsigned getNumMemoryInsts(unsigned Bytes, unsigned MaxBytes,
+ bool HasDwordx3) {
+ unsigned NumInsts = Bytes / MaxBytes;
+ unsigned Rem = Bytes % MaxBytes;
+ if (HasDwordx3 && Rem >= 12) {
+ ++NumInsts;
+ Rem -= 12;
+ }
+ return NumInsts + llvm::popcount(Rem);
+}
+
InstructionCost GCNTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
Align Alignment,
unsigned AddressSpace,
TTI::TargetCostKind CostKind,
TTI::OperandValueInfo OpInfo,
const Instruction *I) const {
- if (VectorType *VecTy = dyn_cast<VectorType>(Src)) {
- if ((Opcode == Instruction::Load || Opcode == Instruction::Store) &&
- CostKind != TTI::TCK_Latency &&
- VecTy->getElementType()->isIntegerTy(8)) {
- return divideCeil(DL.getTypeSizeInBits(VecTy) - 1,
+ Type *EltTy = Src->getScalarType();
+ if ((Opcode != Instruction::Load && Opcode != Instruction::Store) ||
+ CostKind == TTI::TCK_Latency || isa<ScalableVectorType>(Src) ||
+ (!EltTy->isIntOrPtrTy() && !EltTy->isFloatingPointTy()))
+ return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
+ CostKind, OpInfo, I);
+
+ unsigned EltBits = DL.getTypeSizeInBits(EltTy);
+ if (EltBits < 8 || !isPowerOf2_32(EltBits))
+ return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
+ CostKind, OpInfo, I);
+
+ if (AddressSpace == AMDGPUAS::CONSTANT_ADDRESS ||
+ AddressSpace == AMDGPUAS::CONSTANT_ADDRESS_32BIT ||
+ AddressSpace == AMDGPUAS::BUFFER_FAT_POINTER) {
+ if (Src->isVectorTy() && EltTy->isIntegerTy(8))
+ return divideCeil(DL.getTypeSizeInBits(Src) - 1,
getLoadStoreVecRegBitWidth(AddressSpace));
+ return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
+ CostKind, OpInfo, I);
+ }
+
+ unsigned Bytes = DL.getTypeStoreSize(Src);
+ unsigned MaxBytes = 16;
+ bool HasDwordx3 = ST->hasDwordx3LoadStores();
+ switch (AddressSpace) {
----------------
MrSidims wrote:
Will replace it with getLoadStoreVecRegBitWidth plus the flat and LDS special cases.
https://github.com/llvm/llvm-project/pull/233261
More information about the llvm-branch-commits
mailing list