@@ -1100,30 +1100,33 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
1100
1100
}
1101
1101
case ISD::FP_TO_SINT:
1102
1102
case ISD::FP_TO_UINT:
1103
+ // For fp vector to mask, we use:
1104
+ // vfncvt.rtz.x.f.w v9, v8
1105
+ // vand.vi v8, v9, 1
1106
+ // vmsne.vi v0, v8, 0
1107
+ if (Dst->getScalarSizeInBits () == 1 )
1108
+ return 3 ;
1109
+
1110
+ if (std::abs (PowDiff) <= 1 )
1111
+ return 1 ;
1112
+
1113
+ // Counts of narrow/widen instructions.
1114
+ return std::abs (PowDiff);
1115
+
1103
1116
case ISD::SINT_TO_FP:
1104
1117
case ISD::UINT_TO_FP:
1105
- if (Src->getScalarSizeInBits () == 1 || Dst->getScalarSizeInBits () == 1 ) {
1106
- // The cost of convert from or to mask vector is different from other
1107
- // cases. We could not use PowDiff to calculate it.
1108
- // For mask vector to fp, we should use the following instructions:
1109
- // vmv.v.i v8, 0
1110
- // vmerge.vim v8, v8, -1, v0
1111
- // vfcvt.f.x.v v8, v8
1112
-
1113
- // And for fp vector to mask, we use:
1114
- // vfncvt.rtz.x.f.w v9, v8
1115
- // vand.vi v8, v9, 1
1116
- // vmsne.vi v0, v8, 0
1118
+ // For mask vector to fp, we should use the following instructions:
1119
+ // vmv.v.i v8, 0
1120
+ // vmerge.vim v8, v8, -1, v0
1121
+ // vfcvt.f.x.v v8, v8
1122
+ if (Src->getScalarSizeInBits () == 1 )
1117
1123
return 3 ;
1118
- }
1124
+
1119
1125
if (std::abs (PowDiff) <= 1 )
1120
1126
return 1 ;
1121
1127
// Backend could lower (v[sz]ext i8 to double) to vfcvt(v[sz]ext.f8 i8),
1122
1128
// so it only need two conversion.
1123
- if (Src->isIntOrIntVectorTy ())
1124
- return 2 ;
1125
- // Counts of narrow/widen instructions.
1126
- return std::abs (PowDiff);
1129
+ return 2 ;
1127
1130
}
1128
1131
return BaseT::getCastInstrCost (Opcode, Dst, Src, CCH, CostKind, I);
1129
1132
}
0 commit comments