Skip to content

Commit 5d2432f

Browse files
committed
fix the vtype for fcvt
1 parent 1a8c67e commit 5d2432f

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,37 +1058,44 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
10581058
}
10591059
case Intrinsic::sqrt: {
10601060
auto LT = getTypeLegalizationCost(RetTy);
1061-
auto NVT = LT.second;
10621061
if (ST->hasVInstructions() && LT.second.isVector()) {
1063-
SmallVector<unsigned, 3> Opcodes;
1062+
SmallVector<unsigned, 4> ConvOp;
1063+
SmallVector<unsigned, 2> FsqrtOp;
1064+
MVT ConvType = LT.second;
1065+
MVT FsqrtType = LT.second;
10641066
// f16 with zvfhmin and bf16 with zvfbfmin and the type of nxv32[b]f16
10651067
// will be spilt.
10661068
if (LT.second.getVectorElementType() == MVT::bf16) {
10671069
if (LT.second == MVT::nxv32bf16) {
1068-
Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFWCVTBF16_F_F_V,
1069-
RISCV::VFSQRT_V, RISCV::VFSQRT_V,
1070-
RISCV::VFNCVTBF16_F_F_W, RISCV::VFNCVTBF16_F_F_W};
1071-
NVT = MVT::nxv16f32;
1070+
ConvOp = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFWCVTBF16_F_F_V,
1071+
RISCV::VFNCVTBF16_F_F_W, RISCV::VFNCVTBF16_F_F_W};
1072+
FsqrtOp = {RISCV::VFSQRT_V, RISCV::VFSQRT_V};
1073+
ConvType = MVT::nxv16f16;
1074+
FsqrtType = MVT::nxv16f32;
10721075
} else {
1073-
Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFSQRT_V,
1074-
RISCV::VFNCVTBF16_F_F_W};
1075-
NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
1076+
ConvOp = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFNCVTBF16_F_F_W};
1077+
FsqrtOp = {RISCV::VFSQRT_V};
1078+
FsqrtType = TLI->getTypeToPromoteTo(ISD::FSQRT, FsqrtType);
10761079
}
10771080
} else if (LT.second.getVectorElementType() == MVT::f16 &&
10781081
!ST->hasVInstructionsF16()) {
10791082
if (LT.second == MVT::nxv32f16) {
1080-
Opcodes = {RISCV::VFWCVT_F_F_V, RISCV::VFWCVT_F_F_V,
1081-
RISCV::VFSQRT_V, RISCV::VFSQRT_V,
1082-
RISCV::VFNCVT_F_F_W, RISCV::VFNCVT_F_F_W};
1083-
NVT = NVT = MVT::nxv16f32;
1083+
ConvOp = {RISCV::VFWCVT_F_F_V, RISCV::VFWCVT_F_F_V,
1084+
RISCV::VFNCVT_F_F_W, RISCV::VFNCVT_F_F_W};
1085+
FsqrtOp = {RISCV::VFSQRT_V, RISCV::VFSQRT_V};
1086+
ConvType = MVT::nxv16f16;
1087+
FsqrtType = MVT::nxv16f32;
10841088
} else {
1085-
Opcodes = {RISCV::VFWCVT_F_F_V, RISCV::VFSQRT_V, RISCV::VFNCVT_F_F_W};
1086-
NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
1089+
ConvOp = {RISCV::VFWCVT_F_F_V, RISCV::VFNCVT_F_F_W};
1090+
FsqrtOp = {RISCV::VFSQRT_V};
1091+
FsqrtType = TLI->getTypeToPromoteTo(ISD::FSQRT, FsqrtType);
10871092
}
10881093
} else {
1089-
Opcodes = {RISCV::VFSQRT_V};
1094+
FsqrtOp = {RISCV::VFSQRT_V};
10901095
}
1091-
return LT.first * getRISCVInstructionCost(Opcodes, NVT, CostKind);
1096+
1097+
return LT.first * (getRISCVInstructionCost(FsqrtOp, FsqrtType, CostKind) +
1098+
getRISCVInstructionCost(ConvOp, ConvType, CostKind));
10921099
}
10931100
break;
10941101
}

llvm/test/Analysis/CostModel/RISCV/fp-sqrt-pow.ll

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ define void @sqrt() {
77
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %1 = call bfloat @llvm.sqrt.bf16(bfloat poison)
88
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %2 = call <2 x bfloat> @llvm.sqrt.v2bf16(<2 x bfloat> poison)
99
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %3 = call <4 x bfloat> @llvm.sqrt.v4bf16(<4 x bfloat> poison)
10-
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %4 = call <8 x bfloat> @llvm.sqrt.v8bf16(<8 x bfloat> poison)
11-
; CHECK-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %5 = call <16 x bfloat> @llvm.sqrt.v16bf16(<16 x bfloat> poison)
12-
; CHECK-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %6 = call <32 x bfloat> @llvm.sqrt.v32bf16(<32 x bfloat> poison)
10+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %4 = call <8 x bfloat> @llvm.sqrt.v8bf16(<8 x bfloat> poison)
11+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %5 = call <16 x bfloat> @llvm.sqrt.v16bf16(<16 x bfloat> poison)
12+
; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %6 = call <32 x bfloat> @llvm.sqrt.v32bf16(<32 x bfloat> poison)
1313
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %7 = call <vscale x 2 x bfloat> @llvm.sqrt.nxv2bf16(<vscale x 2 x bfloat> poison)
14-
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %8 = call <vscale x 4 x bfloat> @llvm.sqrt.nxv4bf16(<vscale x 4 x bfloat> poison)
15-
; CHECK-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %9 = call <vscale x 8 x bfloat> @llvm.sqrt.nxv8bf16(<vscale x 8 x bfloat> poison)
16-
; CHECK-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %10 = call <vscale x 16 x bfloat> @llvm.sqrt.nxv16bf16(<vscale x 16 x bfloat> poison)
17-
; CHECK-NEXT: Cost Model: Found an estimated cost of 48 for instruction: %11 = call <vscale x 32 x bfloat> @llvm.sqrt.nxv32bf16(<vscale x 32 x bfloat> poison)
14+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %8 = call <vscale x 4 x bfloat> @llvm.sqrt.nxv4bf16(<vscale x 4 x bfloat> poison)
15+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %9 = call <vscale x 8 x bfloat> @llvm.sqrt.nxv8bf16(<vscale x 8 x bfloat> poison)
16+
; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %10 = call <vscale x 16 x bfloat> @llvm.sqrt.nxv16bf16(<vscale x 16 x bfloat> poison)
17+
; CHECK-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %11 = call <vscale x 32 x bfloat> @llvm.sqrt.nxv32bf16(<vscale x 32 x bfloat> poison)
1818
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = call float @llvm.sqrt.f32(float poison)
1919
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %13 = call <2 x float> @llvm.sqrt.v2f32(<2 x float> poison)
2020
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %14 = call <4 x float> @llvm.sqrt.v4f32(<4 x float> poison)
@@ -88,14 +88,14 @@ define void @sqrt_f16() {
8888
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %1 = call half @llvm.sqrt.f16(half poison)
8989
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %2 = call <2 x half> @llvm.sqrt.v2f16(<2 x half> poison)
9090
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %3 = call <4 x half> @llvm.sqrt.v4f16(<4 x half> poison)
91-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %4 = call <8 x half> @llvm.sqrt.v8f16(<8 x half> poison)
92-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %5 = call <16 x half> @llvm.sqrt.v16f16(<16 x half> poison)
93-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %6 = call <32 x half> @llvm.sqrt.v32f16(<32 x half> poison)
91+
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %4 = call <8 x half> @llvm.sqrt.v8f16(<8 x half> poison)
92+
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %5 = call <16 x half> @llvm.sqrt.v16f16(<16 x half> poison)
93+
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %6 = call <32 x half> @llvm.sqrt.v32f16(<32 x half> poison)
9494
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %7 = call <vscale x 2 x half> @llvm.sqrt.nxv2f16(<vscale x 2 x half> poison)
95-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %8 = call <vscale x 4 x half> @llvm.sqrt.nxv4f16(<vscale x 4 x half> poison)
96-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %9 = call <vscale x 8 x half> @llvm.sqrt.nxv8f16(<vscale x 8 x half> poison)
97-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %10 = call <vscale x 16 x half> @llvm.sqrt.nxv16f16(<vscale x 16 x half> poison)
98-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 48 for instruction: %11 = call <vscale x 32 x half> @llvm.sqrt.nxv32f16(<vscale x 32 x half> poison)
95+
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %8 = call <vscale x 4 x half> @llvm.sqrt.nxv4f16(<vscale x 4 x half> poison)
96+
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %9 = call <vscale x 8 x half> @llvm.sqrt.nxv8f16(<vscale x 8 x half> poison)
97+
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %10 = call <vscale x 16 x half> @llvm.sqrt.nxv16f16(<vscale x 16 x half> poison)
98+
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %11 = call <vscale x 32 x half> @llvm.sqrt.nxv32f16(<vscale x 32 x half> poison)
9999
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
100100
;
101101
call half @llvm.sqrt.f16(half poison)

0 commit comments

Comments
 (0)