Skip to content

Commit 1b61788

Browse files
committed
[RISCV][TTI] Use vtype for getRISCVInstructionCost
1 parent 72db3f9 commit 1b61788

File tree

5 files changed

+132
-124
lines changed

5 files changed

+132
-124
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,13 +1301,16 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
13011301
: RISCV::VFNCVT_F_F_W;
13021302
InstructionCost Cost = 0;
13031303
for (; SrcEltSize != DstEltSize;) {
1304-
MVT ElementMVT = (ISD == ISD::TRUNCATE)
1305-
? MVT::getIntegerVT(DstEltSize)
1304+
MVT ElementMVT = (ISD == ISD::TRUNCATE) ? MVT::getIntegerVT(DstEltSize)
1305+
: (ISD == ISD::FP_EXTEND)
1306+
? MVT::getFloatingPointVT(SrcEltSize)
13061307
: MVT::getFloatingPointVT(DstEltSize);
1307-
MVT DstMVT = DstLT.second.changeVectorElementType(ElementMVT);
1308-
DstEltSize =
1309-
(DstEltSize > SrcEltSize) ? DstEltSize >> 1 : DstEltSize << 1;
1310-
Cost += getRISCVInstructionCost(Op, DstMVT, CostKind);
1308+
MVT VTypeMVT = DstLT.second.changeVectorElementType(ElementMVT);
1309+
Cost += getRISCVInstructionCost(Op, VTypeMVT, CostKind);
1310+
if (DstEltSize > SrcEltSize)
1311+
SrcEltSize = SrcEltSize << 1;
1312+
else
1313+
DstEltSize = DstEltSize << 1;
13111314
}
13121315
return Cost;
13131316
}

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
4848
/// actual target hardware.
4949
unsigned getEstimatedVLFor(VectorType *Ty);
5050

51+
/// This function calculates the costs for one or more RVV opcodes based
52+
/// on the vtype and the cost kind.
53+
/// \param Opcodes A list of opcodes of the RVV instruction to evaluate.
54+
/// \param VT The MVT of vtype associated with the RVV instructions.
55+
/// \param CostKind The type of cost to compute.
5156
InstructionCost getRISCVInstructionCost(ArrayRef<unsigned> OpCodes, MVT VT,
5257
TTI::TargetCostKind CostKind);
5358

0 commit comments

Comments
 (0)