From 59960e8db9cf53ef6be7a1f4015be227aff34e3f Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Fri, 19 Aug 2022 12:52:56 -0700 Subject: [PATCH] [RISCV] Factor out getVectorImmCost cost after 0e7ed3 [nfc] --- llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp | 22 ++++++++++++++++------ llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h | 7 +++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index 3a5570c..80c735d 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -512,6 +512,21 @@ InstructionCost RISCVTTIImpl::getExtendedReductionCost( getArithmeticReductionCost(Opcode, ValTy, FMF, CostKind); } +InstructionCost RISCVTTIImpl::getVectorImmCost(VectorType *VecTy, + TTI::OperandValueKind OpInfo, + TTI::OperandValueProperties PropInfo, + TTI::TargetCostKind CostKind) { + assert((OpInfo == TTI::OK_UniformConstantValue || + OpInfo == TTI::OK_NonUniformConstantValue) && "non constant operand?"); + APInt PseudoAddr = APInt::getAllOnes(DL.getPointerSizeInBits()); + // Add a cost of address load + the cost of the vector load. + return RISCVMatInt::getIntMatCost(PseudoAddr, DL.getPointerSizeInBits(), + getST()->getFeatureBits()) + + getMemoryOpCost(Instruction::Load, VecTy, DL.getABITypeAlign(VecTy), + /*AddressSpace=*/0, CostKind); +} + + InstructionCost RISCVTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, @@ -522,12 +537,7 @@ InstructionCost RISCVTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, if (Opcode == Instruction::Store && isa(Src) && (OpdInfo == TTI::OK_UniformConstantValue || OpdInfo == TTI::OK_NonUniformConstantValue)) { - APInt PseudoAddr = APInt::getAllOnes(DL.getPointerSizeInBits()); - // Add a cost of address load + the cost of the vector load. - Cost += RISCVMatInt::getIntMatCost(PseudoAddr, DL.getPointerSizeInBits(), - getST()->getFeatureBits()) + - getMemoryOpCost(Instruction::Load, Src, DL.getABITypeAlign(Src), - /*AddressSpace=*/0, CostKind); + Cost += getVectorImmCost(cast(Src), OpdInfo, TTI::OP_None, CostKind); } return Cost + BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, CostKind, OpdInfo, I); diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h index b9b07f1..aa39f63 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h @@ -51,6 +51,13 @@ public: : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), TLI(ST->getTargetLowering()) {} + /// Return the cost of materializing a vector immediate, assuming it does + /// not get folded into the using instruction(s). + InstructionCost getVectorImmCost(VectorType *VecTy, + TTI::OperandValueKind OpInfo, + TTI::OperandValueProperties PropInfo, + TTI::TargetCostKind CostKind); + InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind); InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx, -- 2.7.4