[RISCV] Rename getVectorImmCost to getStoreImmCost [nfc]
authorPhilip Reames <preames@rivosinc.com>
Tue, 27 Sep 2022 15:20:49 +0000 (08:20 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 27 Sep 2022 15:22:13 +0000 (08:22 -0700)
My original intent had been to reuse this for arithmetic instructions as well, but due to the availability of a immediate splat encoding there, we will need different heuristics.  So specialize the existing code for the store case.

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

index 88c5931..94852c5 100644 (file)
@@ -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<VectorType>(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<VectorType>(Src) && OpInfo.isConstant())
-    Cost += getVectorImmCost(cast<VectorType>(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);
 }
index b49bafb..704d0db 100644 (file)
@@ -51,11 +51,10 @@ 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::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);