[llvm] b66310f - [RISCV][TTI] Split costing of [u/s]int_to_fp from fp_to_[u/s]int [nfc] (#101029)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 09:32:39 PDT 2024
Author: Philip Reames
Date: 2024-07-29T09:32:36-07:00
New Revision: b66310f938f36557f44042e300e5894e39297b2b
URL: https://github.com/llvm/llvm-project/commit/b66310f938f36557f44042e300e5894e39297b2b
DIFF: https://github.com/llvm/llvm-project/commit/b66310f938f36557f44042e300e5894e39297b2b.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 0fcaac060569c..a61a9f10be86c 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1100,30 +1100,33 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
}
case ISD::FP_TO_SINT:
case ISD::FP_TO_UINT:
+ // For fp vector to mask, we use:
+ // vfncvt.rtz.x.f.w v9, v8
+ // vand.vi v8, v9, 1
+ // vmsne.vi v0, v8, 0
+ if (Dst->getScalarSizeInBits() == 1)
+ return 3;
+
+ if (std::abs(PowDiff) <= 1)
+ return 1;
+
+ // Counts of narrow/widen instructions.
+ return std::abs(PowDiff);
+
case ISD::SINT_TO_FP:
case ISD::UINT_TO_FP:
- if (Src->getScalarSizeInBits() == 1 || Dst->getScalarSizeInBits() == 1) {
- // The cost of convert from or to mask vector is
diff erent from other
- // cases. We could not use PowDiff to calculate it.
- // For mask vector to fp, we should use the following instructions:
- // vmv.v.i v8, 0
- // vmerge.vim v8, v8, -1, v0
- // vfcvt.f.x.v v8, v8
-
- // And for fp vector to mask, we use:
- // vfncvt.rtz.x.f.w v9, v8
- // vand.vi v8, v9, 1
- // vmsne.vi v0, v8, 0
+ // For mask vector to fp, we should use the following instructions:
+ // vmv.v.i v8, 0
+ // vmerge.vim v8, v8, -1, v0
+ // vfcvt.f.x.v v8, v8
+ if (Src->getScalarSizeInBits() == 1)
return 3;
- }
+
if (std::abs(PowDiff) <= 1)
return 1;
// Backend could lower (v[sz]ext i8 to double) to vfcvt(v[sz]ext.f8 i8),
// so it only need two conversion.
- if (Src->isIntOrIntVectorTy())
- return 2;
- // Counts of narrow/widen instructions.
- return std::abs(PowDiff);
+ return 2;
}
return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
}
More information about the llvm-commits
mailing list