Skip to content

Commit 6fe7249

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 5c663aa commit 6fe7249

File tree

6 files changed

+566
-556
lines changed

6 files changed

+566
-556
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,23 +906,33 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
906906
if (!IsVectorType || !IsTypeLegal)
907907
return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
908908

909+
std::pair<InstructionCost, MVT> DstLT = getTypeLegalizationCost(Dst);
910+
909911
int ISD = TLI->InstructionOpcodeToISD(Opcode);
910912
assert(ISD && "Invalid opcode");
911913

912-
// FIXME: Need to consider vsetvli and lmul.
913914
int PowDiff = (int)Log2_32(Dst->getScalarSizeInBits()) -
914915
(int)Log2_32(Src->getScalarSizeInBits());
915916
switch (ISD) {
916917
case ISD::SIGN_EXTEND:
917-
case ISD::ZERO_EXTEND:
918-
if (Src->getScalarSizeInBits() == 1) {
918+
case ISD::ZERO_EXTEND: {
919+
const unsigned SrcEltSize = Src->getScalarSizeInBits();
920+
if (SrcEltSize == 1) {
919921
// We do not use vsext/vzext to extend from mask vector.
920922
// Instead we use the following instructions to extend from mask vector:
921923
// vmv.v.i v8, 0
922924
// vmerge.vim v8, v8, -1, v0
923-
return 2;
925+
return getRISCVInstructionCost({RISCV::VMV_V_I, RISCV::VMERGE_VIM},
926+
DstLT.second, CostKind);
924927
}
925-
return 1;
928+
if (PowDiff > 3)
929+
return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
930+
unsigned SExtOp[] = {RISCV::VSEXT_VF2, RISCV::VSEXT_VF4, RISCV::VSEXT_VF8};
931+
unsigned ZExtOp[] = {RISCV::VZEXT_VF2, RISCV::VZEXT_VF4, RISCV::VZEXT_VF8};
932+
unsigned Op =
933+
(ISD == ISD::SIGN_EXTEND) ? SExtOp[PowDiff - 1] : ZExtOp[PowDiff - 1];
934+
return getRISCVInstructionCost(Op, DstLT.second, CostKind);
935+
}
926936
case ISD::TRUNCATE:
927937
if (Dst->getScalarSizeInBits() == 1) {
928938
// We do not use several vncvt to truncate to mask vector. So we could

0 commit comments

Comments
 (0)