diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index 88c5931d2d886..94852c53fe3c0 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -656,15 +656,21 @@ InstructionCost RISCVTTIImpl::getExtendedReductionCost( getArithmeticReductionCost(Opcode, ValTy, FMF, CostKind); } -InstructionCost RISCVTTIImpl::getVectorImmCost(VectorType *VecTy, - TTI::OperandValueInfo OpInfo, - TTI::TargetCostKind CostKind) { +InstructionCost RISCVTTIImpl::getStoreImmCost(Type *Ty, + TTI::OperandValueInfo OpInfo, + TTI::TargetCostKind CostKind) { assert(OpInfo.isConstant() && "non constant operand?"); + if (!isa(Ty)) + // FIXME: We need to account for immediate materialization here, but doing + // a decent job requires more knowledge about the immediate than we + // currently have here. + return 0; + 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), + getMemoryOpCost(Instruction::Load, Ty, DL.getABITypeAlign(Ty), /*AddressSpace=*/0, CostKind); } @@ -676,8 +682,8 @@ InstructionCost RISCVTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, TTI::OperandValueInfo OpInfo, const Instruction *I) { InstructionCost Cost = 0; - if (Opcode == Instruction::Store && isa(Src) && OpInfo.isConstant()) - Cost += getVectorImmCost(cast(Src), OpInfo, CostKind); + if (Opcode == Instruction::Store && OpInfo.isConstant()) + Cost += getStoreImmCost(Src, OpInfo, CostKind); return Cost + BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, CostKind, OpInfo, I); } diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h index b49bafb7db941..704d0dbdffaff 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h @@ -51,11 +51,10 @@ class RISCVTTIImpl : public BasicTTIImplBase { : 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::OperandValueInfo OpInfo, - TTI::TargetCostKind CostKind); + /// Return the cost of materializing an immediate for a value operand of + /// a store instruction. + InstructionCost getStoreImmCost(Type *VecTy, TTI::OperandValueInfo OpInfo, + TTI::TargetCostKind CostKind); InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind);