Skip to content

Commit 1fe4655

Browse files
committed
Add cost for fsqrt of type nxv32[b]f16
1 parent 0b5f44e commit 1fe4655

File tree

2 files changed

+60
-37
lines changed

2 files changed

+60
-37
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,15 +1060,28 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
10601060
auto NVT = LT.second;
10611061
if (ST->hasVInstructions() && LT.second.isVector()) {
10621062
SmallVector<unsigned, 3> Opcodes;
1063-
// f16 with zvfhmin and bf16 with zvfbfmin
1063+
// f16 with zvfhmin and bf16 with zvfbfmin and the type of nxv32[b]f16
1064+
// will be spilt.
10641065
if (LT.second.getVectorElementType() == MVT::bf16) {
1065-
Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFSQRT_V,
1066-
RISCV::VFNCVTBF16_F_F_W};
1067-
NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
1066+
if (LT.second == MVT::nxv32bf16) {
1067+
Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFWCVTBF16_F_F_V,
1068+
RISCV::VFSQRT_V, RISCV::VFSQRT_V,
1069+
RISCV::VFNCVTBF16_F_F_W, RISCV::VFNCVTBF16_F_F_W};
1070+
} else {
1071+
Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFSQRT_V,
1072+
RISCV::VFNCVTBF16_F_F_W};
1073+
NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
1074+
}
10681075
} else if (LT.second.getVectorElementType() == MVT::f16 &&
10691076
!ST->hasVInstructionsF16()) {
1070-
Opcodes = {RISCV::VFWCVT_F_F_V, RISCV::VFSQRT_V, RISCV::VFNCVT_F_F_W};
1071-
NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
1077+
if (LT.second == MVT::nxv32f16) {
1078+
Opcodes = {RISCV::VFWCVT_F_F_V, RISCV::VFWCVT_F_F_V,
1079+
RISCV::VFSQRT_V, RISCV::VFSQRT_V,
1080+
RISCV::VFNCVT_F_F_W, RISCV::VFNCVT_F_F_W};
1081+
} else {
1082+
Opcodes = {RISCV::VFWCVT_F_F_V, RISCV::VFSQRT_V, RISCV::VFNCVT_F_F_W};
1083+
NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT);
1084+
}
10721085
} else {
10731086
Opcodes = {RISCV::VFSQRT_V};
10741087
}

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

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,44 @@ define void @sqrt() {
99
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %3 = call <4 x bfloat> @llvm.sqrt.v4bf16(<4 x bfloat> undef)
1010
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %4 = call <8 x bfloat> @llvm.sqrt.v8bf16(<8 x bfloat> undef)
1111
; CHECK-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %5 = call <16 x bfloat> @llvm.sqrt.v16bf16(<16 x bfloat> undef)
12-
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %6 = call <vscale x 2 x bfloat> @llvm.sqrt.nxv2bf16(<vscale x 2 x bfloat> undef)
13-
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %7 = call <vscale x 4 x bfloat> @llvm.sqrt.nxv4bf16(<vscale x 4 x bfloat> undef)
14-
; CHECK-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %8 = call <vscale x 8 x bfloat> @llvm.sqrt.nxv8bf16(<vscale x 8 x bfloat> undef)
15-
; CHECK-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %9 = call <vscale x 16 x bfloat> @llvm.sqrt.nxv16bf16(<vscale x 16 x bfloat> undef)
16-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %10 = call float @llvm.sqrt.f32(float undef)
17-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %11 = call <2 x float> @llvm.sqrt.v2f32(<2 x float> undef)
18-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = call <4 x float> @llvm.sqrt.v4f32(<4 x float> undef)
19-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %13 = call <8 x float> @llvm.sqrt.v8f32(<8 x float> undef)
20-
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %14 = call <16 x float> @llvm.sqrt.v16f32(<16 x float> undef)
21-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %15 = call <vscale x 1 x float> @llvm.sqrt.nxv1f32(<vscale x 1 x float> undef)
22-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %16 = call <vscale x 2 x float> @llvm.sqrt.nxv2f32(<vscale x 2 x float> undef)
23-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %17 = call <vscale x 4 x float> @llvm.sqrt.nxv4f32(<vscale x 4 x float> undef)
24-
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %18 = call <vscale x 8 x float> @llvm.sqrt.nxv8f32(<vscale x 8 x float> undef)
25-
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %19 = call <vscale x 16 x float> @llvm.sqrt.nxv16f32(<vscale x 16 x float> undef)
26-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %20 = call double @llvm.sqrt.f64(double undef)
27-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %21 = call <2 x double> @llvm.sqrt.v2f64(<2 x double> undef)
28-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %22 = call <4 x double> @llvm.sqrt.v4f64(<4 x double> undef)
29-
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %23 = call <8 x double> @llvm.sqrt.v8f64(<8 x double> undef)
30-
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %24 = call <16 x double> @llvm.sqrt.v16f64(<16 x double> undef)
31-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %25 = call <vscale x 1 x double> @llvm.sqrt.nxv1f64(<vscale x 1 x double> undef)
32-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %26 = call <vscale x 2 x double> @llvm.sqrt.nxv2f64(<vscale x 2 x double> undef)
33-
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %27 = call <vscale x 4 x double> @llvm.sqrt.nxv4f64(<vscale x 4 x double> undef)
34-
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %28 = call <vscale x 8 x double> @llvm.sqrt.nxv8f64(<vscale x 8 x double> undef)
12+
; CHECK-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %6 = call <32 x bfloat> @llvm.sqrt.v32bf16(<32 x bfloat> undef)
13+
; 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> undef)
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> undef)
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> undef)
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> undef)
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> undef)
18+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = call float @llvm.sqrt.f32(float undef)
19+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %13 = call <2 x float> @llvm.sqrt.v2f32(<2 x float> undef)
20+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %14 = call <4 x float> @llvm.sqrt.v4f32(<4 x float> undef)
21+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %15 = call <8 x float> @llvm.sqrt.v8f32(<8 x float> undef)
22+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %16 = call <16 x float> @llvm.sqrt.v16f32(<16 x float> undef)
23+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %17 = call <vscale x 1 x float> @llvm.sqrt.nxv1f32(<vscale x 1 x float> undef)
24+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %18 = call <vscale x 2 x float> @llvm.sqrt.nxv2f32(<vscale x 2 x float> undef)
25+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %19 = call <vscale x 4 x float> @llvm.sqrt.nxv4f32(<vscale x 4 x float> undef)
26+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %20 = call <vscale x 8 x float> @llvm.sqrt.nxv8f32(<vscale x 8 x float> undef)
27+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %21 = call <vscale x 16 x float> @llvm.sqrt.nxv16f32(<vscale x 16 x float> undef)
28+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %22 = call double @llvm.sqrt.f64(double undef)
29+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %23 = call <2 x double> @llvm.sqrt.v2f64(<2 x double> undef)
30+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %24 = call <4 x double> @llvm.sqrt.v4f64(<4 x double> undef)
31+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %25 = call <8 x double> @llvm.sqrt.v8f64(<8 x double> undef)
32+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %26 = call <16 x double> @llvm.sqrt.v16f64(<16 x double> undef)
33+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %27 = call <vscale x 1 x double> @llvm.sqrt.nxv1f64(<vscale x 1 x double> undef)
34+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %28 = call <vscale x 2 x double> @llvm.sqrt.nxv2f64(<vscale x 2 x double> undef)
35+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %29 = call <vscale x 4 x double> @llvm.sqrt.nxv4f64(<vscale x 4 x double> undef)
36+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %30 = call <vscale x 8 x double> @llvm.sqrt.nxv8f64(<vscale x 8 x double> undef)
3537
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
3638
;
3739
call bfloat @llvm.sqrt.bf16(bfloat undef)
3840
call <2 x bfloat> @llvm.sqrt.v2bf16(<2 x bfloat> undef)
3941
call <4 x bfloat> @llvm.sqrt.v4bf16(<4 x bfloat> undef)
4042
call <8 x bfloat> @llvm.sqrt.v8bf16(<8 x bfloat> undef)
4143
call <16 x bfloat> @llvm.sqrt.v16bf16(<16 x bfloat> undef)
44+
call <32 x bfloat> @llvm.sqrt.v32bf16(<32 x bfloat> undef)
4245
call <vscale x 2 x bfloat> @llvm.sqrt.nxv2bf16(<vscale x 2 x bfloat> undef)
4346
call <vscale x 4 x bfloat> @llvm.sqrt.nxv4bf16(<vscale x 4 x bfloat> undef)
4447
call <vscale x 8 x bfloat> @llvm.sqrt.nxv8bf16(<vscale x 8 x bfloat> undef)
4548
call <vscale x 16 x bfloat> @llvm.sqrt.nxv16bf16(<vscale x 16 x bfloat> undef)
49+
call <vscale x 32 x bfloat> @llvm.sqrt.nxv32bf16(<vscale x 32 x bfloat> undef)
4650
call float @llvm.sqrt.f32(float undef)
4751
call <2 x float> @llvm.sqrt.v2f32(<2 x float> undef)
4852
call <4 x float> @llvm.sqrt.v4f32(<4 x float> undef)
@@ -72,10 +76,12 @@ define void @sqrt_f16() {
7276
; ZVFH-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %3 = call <4 x half> @llvm.sqrt.v4f16(<4 x half> undef)
7377
; ZVFH-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = call <8 x half> @llvm.sqrt.v8f16(<8 x half> undef)
7478
; ZVFH-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %5 = call <16 x half> @llvm.sqrt.v16f16(<16 x half> undef)
75-
; ZVFH-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = call <vscale x 2 x half> @llvm.sqrt.nxv2f16(<vscale x 2 x half> undef)
76-
; ZVFH-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = call <vscale x 4 x half> @llvm.sqrt.nxv4f16(<vscale x 4 x half> undef)
77-
; ZVFH-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %8 = call <vscale x 8 x half> @llvm.sqrt.nxv8f16(<vscale x 8 x half> undef)
78-
; ZVFH-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %9 = call <vscale x 16 x half> @llvm.sqrt.nxv16f16(<vscale x 16 x half> undef)
79+
; ZVFH-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %6 = call <32 x half> @llvm.sqrt.v32f16(<32 x half> undef)
80+
; ZVFH-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = call <vscale x 2 x half> @llvm.sqrt.nxv2f16(<vscale x 2 x half> undef)
81+
; ZVFH-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %8 = call <vscale x 4 x half> @llvm.sqrt.nxv4f16(<vscale x 4 x half> undef)
82+
; ZVFH-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %9 = call <vscale x 8 x half> @llvm.sqrt.nxv8f16(<vscale x 8 x half> undef)
83+
; ZVFH-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %10 = call <vscale x 16 x half> @llvm.sqrt.nxv16f16(<vscale x 16 x half> undef)
84+
; ZVFH-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %11 = call <vscale x 32 x half> @llvm.sqrt.nxv32f16(<vscale x 32 x half> undef)
7985
; ZVFH-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
8086
;
8187
; ZVFHMIN-LABEL: 'sqrt_f16'
@@ -84,21 +90,25 @@ define void @sqrt_f16() {
8490
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %3 = call <4 x half> @llvm.sqrt.v4f16(<4 x half> undef)
8591
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %4 = call <8 x half> @llvm.sqrt.v8f16(<8 x half> undef)
8692
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %5 = call <16 x half> @llvm.sqrt.v16f16(<16 x half> undef)
87-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %6 = call <vscale x 2 x half> @llvm.sqrt.nxv2f16(<vscale x 2 x half> undef)
88-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %7 = call <vscale x 4 x half> @llvm.sqrt.nxv4f16(<vscale x 4 x half> undef)
89-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %8 = call <vscale x 8 x half> @llvm.sqrt.nxv8f16(<vscale x 8 x half> undef)
90-
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %9 = call <vscale x 16 x half> @llvm.sqrt.nxv16f16(<vscale x 16 x half> undef)
93+
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %6 = call <32 x half> @llvm.sqrt.v32f16(<32 x half> undef)
94+
; 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> undef)
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> undef)
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> undef)
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> undef)
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> undef)
9199
; ZVFHMIN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
92100
;
93101
call half @llvm.sqrt.f16(half undef)
94102
call <2 x half> @llvm.sqrt.v2f16(<2 x half> undef)
95103
call <4 x half> @llvm.sqrt.v4f16(<4 x half> undef)
96104
call <8 x half> @llvm.sqrt.v8f16(<8 x half> undef)
97105
call <16 x half> @llvm.sqrt.v16f16(<16 x half> undef)
106+
call <32 x half> @llvm.sqrt.v32f16(<32 x half> undef)
98107
call <vscale x 2 x half> @llvm.sqrt.nxv2f16(<vscale x 2 x half> undef)
99108
call <vscale x 4 x half> @llvm.sqrt.nxv4f16(<vscale x 4 x half> undef)
100109
call <vscale x 8 x half> @llvm.sqrt.nxv8f16(<vscale x 8 x half> undef)
101110
call <vscale x 16 x half> @llvm.sqrt.nxv16f16(<vscale x 16 x half> undef)
111+
call <vscale x 32 x half> @llvm.sqrt.nxv32f16(<vscale x 32 x half> undef)
102112
ret void
103113
}
104114

0 commit comments

Comments
 (0)