[llvm] [RISCV][CostModel] Add cost for fabs/fsqrt of type bf16/f16 (PR #118608)
Shih-Po Hung via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 7 17:54:58 PST 2025
================
@@ -1060,15 +1060,28 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
auto NVT = LT.second;
if (ST->hasVInstructions() && LT.second.isVector()) {
SmallVector<unsigned, 3> Opcodes;
- // f16 with zvfhmin and bf16 with zvfbfmin
+ // f16 with zvfhmin and bf16 with zvfbfmin and the type of nxv32[b]f16
+ // will be spilt.
if (LT.second.getVectorElementType() == MVT::bf16) {
- Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFSQRT_V,
- RISCV::VFNCVTBF16_F_F_W};
- NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
+ if (LT.second == MVT::nxv32bf16) {
+ Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFWCVTBF16_F_F_V,
+ RISCV::VFSQRT_V, RISCV::VFSQRT_V,
+ RISCV::VFNCVTBF16_F_F_W, RISCV::VFNCVTBF16_F_F_W};
+ } else {
+ Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFSQRT_V,
+ RISCV::VFNCVTBF16_F_F_W};
+ NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
+ }
} else if (LT.second.getVectorElementType() == MVT::f16 &&
!ST->hasVInstructionsF16()) {
- Opcodes = {RISCV::VFWCVT_F_F_V, RISCV::VFSQRT_V, RISCV::VFNCVT_F_F_W};
- NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
+ if (LT.second == MVT::nxv32f16) {
+ Opcodes = {RISCV::VFWCVT_F_F_V, RISCV::VFWCVT_F_F_V,
+ RISCV::VFSQRT_V, RISCV::VFSQRT_V,
----------------
arcbbb wrote:
hmm.. I think vfwcvtbf16.f.f.v is the same with vfwcvt.f.f.v.
```
4.4. vfwcvtbf16.f.f.v
Synopsis
Vector convert BF16 to FP32
Description
This instruction is similar to vfwcvt.f.f.v which converts a floating-point value in an SEW-width
format into a 2*SEW-width format. However, here the SEW-width format is limited to BF16.
```
https://github.com/llvm/llvm-project/pull/118608
More information about the llvm-commits
mailing list