@@ -909,23 +909,33 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
909
909
if (!IsTypeLegal)
910
910
return BaseT::getCastInstrCost (Opcode, Dst, Src, CCH, CostKind, I);
911
911
912
+ std::pair<InstructionCost, MVT> DstLT = getTypeLegalizationCost (Dst);
913
+
912
914
int ISD = TLI->InstructionOpcodeToISD (Opcode);
913
915
assert (ISD && " Invalid opcode" );
914
916
915
- // FIXME: Need to consider vsetvli and lmul.
916
917
int PowDiff = (int )Log2_32 (Dst->getScalarSizeInBits ()) -
917
918
(int )Log2_32 (Src->getScalarSizeInBits ());
918
919
switch (ISD) {
919
920
case ISD::SIGN_EXTEND:
920
- case ISD::ZERO_EXTEND:
921
- if (Src->getScalarSizeInBits () == 1 ) {
921
+ case ISD::ZERO_EXTEND: {
922
+ const unsigned SrcEltSize = Src->getScalarSizeInBits ();
923
+ if (SrcEltSize == 1 ) {
922
924
// We do not use vsext/vzext to extend from mask vector.
923
925
// Instead we use the following instructions to extend from mask vector:
924
926
// vmv.v.i v8, 0
925
927
// vmerge.vim v8, v8, -1, v0
926
- return 2 ;
928
+ return getRISCVInstructionCost ({RISCV::VMV_V_I, RISCV::VMERGE_VIM},
929
+ DstLT.second , CostKind);
927
930
}
928
- return 1 ;
931
+ if (PowDiff > 3 )
932
+ return BaseT::getCastInstrCost (Opcode, Dst, Src, CCH, CostKind, I);
933
+ unsigned SExtOp[] = {RISCV::VSEXT_VF2, RISCV::VSEXT_VF4, RISCV::VSEXT_VF8};
934
+ unsigned ZExtOp[] = {RISCV::VZEXT_VF2, RISCV::VZEXT_VF4, RISCV::VZEXT_VF8};
935
+ unsigned Op =
936
+ (ISD == ISD::SIGN_EXTEND) ? SExtOp[PowDiff - 1 ] : ZExtOp[PowDiff - 1 ];
937
+ return getRISCVInstructionCost (Op, DstLT.second , CostKind);
938
+ }
929
939
case ISD::TRUNCATE:
930
940
if (Dst->getScalarSizeInBits () == 1 ) {
931
941
// We do not use several vncvt to truncate to mask vector. So we could
0 commit comments