Skip to content

Commit b66310f

Browse files
authored
[RISCV][TTI] Split costing of [u/s]int_to_fp from fp_to_[u/s]int [nfc] (#101029)
The amount of code sharing between them is fairly small, and the split version is much easier to read.
1 parent 7b3db55 commit b66310f

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,30 +1100,33 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
11001100
}
11011101
case ISD::FP_TO_SINT:
11021102
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+
11031116
case ISD::SINT_TO_FP:
11041117
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)
11171123
return 3;
1118-
}
1124+
11191125
if (std::abs(PowDiff) <= 1)
11201126
return 1;
11211127
// Backend could lower (v[sz]ext i8 to double) to vfcvt(v[sz]ext.f8 i8),
11221128
// 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;
11271130
}
11281131
return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
11291132
}

0 commit comments

Comments
 (0)