@@ -897,6 +897,7 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
897
897
TTI::CastContextHint CCH,
898
898
TTI::TargetCostKind CostKind,
899
899
const Instruction *I) {
900
+ std::pair<InstructionCost, MVT> DstLT = getTypeLegalizationCost (Dst);
900
901
if (isa<VectorType>(Dst) && isa<VectorType>(Src)) {
901
902
// FIXME: Need to compute legalizing cost for illegal types.
902
903
if (!isTypeLegal (Src) || !isTypeLegal (Dst))
@@ -915,15 +916,21 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
915
916
(int )Log2_32 (Src->getScalarSizeInBits ());
916
917
switch (ISD) {
917
918
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
+ }
927
934
case ISD::TRUNCATE:
928
935
if (Dst->getScalarSizeInBits () == 1 ) {
929
936
// We do not use several vncvt to truncate to mask vector. So we could
0 commit comments