@@ -1145,16 +1145,13 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
11451145 MVT ElementVT = MVT::getIntegerVT (SrcEltSize >> 1 );
11461146 MVT VecVT = DstLT.second .changeVectorElementType (ElementVT);
11471147 Cost += getRISCVInstructionCost (FNCVT, VecVT, CostKind);
1148- }
1149- if ((SrcEltSize >> 1 ) > DstEltSize) {
1150- // For mask type, we use:
1151- // vand.vi v8, v9, 1
1152- // vmsne.vi v0, v8, 0
1153- VectorType *VecTy =
1154- VectorType::get (IntegerType::get (Dst->getContext (), SrcEltSize >> 1 ),
1155- cast<VectorType>(Dst)->getElementCount ());
1156- Cost +=
1157- getCastInstrCost (Instruction::Trunc, Dst, VecTy, CCH, CostKind, I);
1148+ if ((SrcEltSize >> 1 ) > DstEltSize) {
1149+ VectorType *VecTy = VectorType::get (
1150+ IntegerType::get (Dst->getContext (), SrcEltSize >> 1 ),
1151+ cast<VectorType>(Dst)->getElementCount ());
1152+ Cost +=
1153+ getCastInstrCost (Instruction::Trunc, Dst, VecTy, CCH, CostKind, I);
1154+ }
11581155 }
11591156 return Cost;
11601157 }
@@ -1183,25 +1180,19 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
11831180 return Cost;
11841181 }
11851182
1186- if ((DstEltSize >> 1 ) > SrcEltSize) {
1187- // Do pre-widening before converting:
1188- // 1. Backend could lower (v[sz]ext i8 to double) to
1189- // vfcvt(v[sz]ext.f8 i8),
1190- // 2. For mask vector to fp, we should use the following instructions:
1191- // vmv.v.i v8, 0
1192- // vmerge.vim v8, v8, -1, v0
1193- SrcEltSize = DstEltSize >> 1 ;
1194- VectorType *VecTy =
1195- VectorType::get (IntegerType::get (Dst->getContext (), SrcEltSize),
1196- cast<VectorType>(Dst)->getElementCount ());
1197- unsigned Op = IsSigned ? Instruction::SExt : Instruction::ZExt;
1198- Cost += getCastInstrCost (Op, VecTy, Src, CCH, CostKind, I);
1199- }
12001183 if (DstEltSize == SrcEltSize)
12011184 Cost += getRISCVInstructionCost (FCVT, DstLT.second , CostKind);
1202- else if (DstEltSize > SrcEltSize)
1185+ else if (DstEltSize > SrcEltSize) {
1186+ if ((DstEltSize >> 1 ) > SrcEltSize) {
1187+ SrcEltSize = DstEltSize >> 1 ;
1188+ VectorType *VecTy =
1189+ VectorType::get (IntegerType::get (Dst->getContext (), SrcEltSize),
1190+ cast<VectorType>(Dst)->getElementCount ());
1191+ unsigned Op = IsSigned ? Instruction::SExt : Instruction::ZExt;
1192+ Cost += getCastInstrCost (Op, VecTy, Src, CCH, CostKind, I);
1193+ }
12031194 Cost += getRISCVInstructionCost (FWCVT, DstLT.second , CostKind);
1204- else
1195+ } else
12051196 Cost += getRISCVInstructionCost (FNCVT, DstLT.second , CostKind);
12061197 return Cost;
12071198 }
0 commit comments