Skip to content

Commit 046ad44

Browse files
committed
[RISCV][TTI] Scale the cost of the sext/zext with LMUL
Use the destination data type to measure the LMUL size for latency/throughput cost
1 parent ce73b16 commit 046ad44

File tree

6 files changed

+567
-560
lines changed

6 files changed

+567
-560
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
897897
TTI::CastContextHint CCH,
898898
TTI::TargetCostKind CostKind,
899899
const Instruction *I) {
900+
std::pair<InstructionCost, MVT> DstLT = getTypeLegalizationCost(Dst);
900901
if (isa<VectorType>(Dst) && isa<VectorType>(Src)) {
901902
// FIXME: Need to compute legalizing cost for illegal types.
902903
if (!isTypeLegal(Src) || !isTypeLegal(Dst))
@@ -915,15 +916,21 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
915916
(int)Log2_32(Src->getScalarSizeInBits());
916917
switch (ISD) {
917918
case ISD::SIGN_EXTEND:
918-
case ISD::ZERO_EXTEND:
919-
if (Src->getScalarSizeInBits() == 1) {
920-
// We do not use vsext/vzext to extend from mask vector.
921-
// Instead we use the following instructions to extend from mask vector:
922-
// vmv.v.i v8, 0
923-
// vmerge.vim v8, v8, -1, v0
924-
return 2;
925-
}
926-
return 1;
919+
case ISD::ZERO_EXTEND: {
920+
const unsigned SrcEltSize = Src->getScalarSizeInBits();
921+
if (SrcEltSize == 1)
922+
return getRISCVInstructionCost({RISCV::VMV_V_I, RISCV::VMERGE_VIM},
923+
DstLT.second, CostKind);
924+
if (PowDiff > 3)
925+
return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
926+
unsigned SExtOp[] = {RISCV::VSEXT_VF2, RISCV::VSEXT_VF4,
927+
RISCV::VSEXT_VF8};
928+
unsigned ZExtOp[] = {RISCV::VZEXT_VF2, RISCV::VZEXT_VF4,
929+
RISCV::VZEXT_VF8};
930+
unsigned Op =
931+
(ISD == ISD::SIGN_EXTEND) ? SExtOp[PowDiff - 1] : ZExtOp[PowDiff - 1];
932+
return getRISCVInstructionCost(Op, DstLT.second, CostKind);
933+
}
927934
case ISD::TRUNCATE:
928935
if (Dst->getScalarSizeInBits() == 1) {
929936
// We do not use several vncvt to truncate to mask vector. So we could

0 commit comments

Comments
 (0)