Skip to content

Commit 97523e5

Browse files
authored
[RISCV][TTI] Scale the cost of intrinsic stepvector with LMUL (#87301)
Use the return type to measure the LMUL size for latency/throughput cost
1 parent 7e2a1d6 commit 97523e5

File tree

2 files changed

+61
-91
lines changed

2 files changed

+61
-91
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,14 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
861861
}
862862
// TODO: add more intrinsic
863863
case Intrinsic::experimental_stepvector: {
864-
unsigned Cost = 1; // vid
865864
auto LT = getTypeLegalizationCost(RetTy);
866-
return Cost + (LT.first - 1);
865+
// Legalisation of illegal types involves an `index' instruction plus
866+
// (LT.first - 1) vector adds.
867+
if (ST->hasVInstructions())
868+
return getRISCVInstructionCost(RISCV::VID_V, LT.second, CostKind) +
869+
(LT.first - 1) *
870+
getRISCVInstructionCost(RISCV::VADD_VX, LT.second, CostKind);
871+
return 1 + (LT.first - 1);
867872
}
868873
case Intrinsic::vp_rint: {
869874
// RISC-V target uses at least 5 instructions to lower rounding intrinsics.

llvm/test/Analysis/CostModel/RISCV/stepvector.ll

Lines changed: 54 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,98 +4,60 @@
44

55
define void @stepvector() {
66
; CHECK-LABEL: 'stepvector'
7-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %zero = call <vscale x 1 x i8> @llvm.experimental.stepvector.nxv1i8()
8-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %1 = call <vscale x 2 x i8> @llvm.experimental.stepvector.nxv2i8()
9-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %2 = call <vscale x 4 x i8> @llvm.experimental.stepvector.nxv4i8()
10-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %3 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
7+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %1 = call <vscale x 1 x i8> @llvm.experimental.stepvector.nxv1i8()
8+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %2 = call <vscale x 2 x i8> @llvm.experimental.stepvector.nxv2i8()
9+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %3 = call <vscale x 4 x i8> @llvm.experimental.stepvector.nxv4i8()
1110
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
12-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %5 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
13-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
14-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
15-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %8 = call <vscale x 16 x i8> @llvm.experimental.stepvector.nxv16i8()
16-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %9 = call <vscale x 32 x i8> @llvm.experimental.stepvector.nxv32i8()
17-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %10 = call <vscale x 64 x i8> @llvm.experimental.stepvector.nxv64i8()
18-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %11 = call <vscale x 1 x i16> @llvm.experimental.stepvector.nxv1i16()
19-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = call <vscale x 2 x i16> @llvm.experimental.stepvector.nxv2i16()
20-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %13 = call <vscale x 4 x i16> @llvm.experimental.stepvector.nxv4i16()
21-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %14 = call <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
22-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %15 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
23-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %16 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
24-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %17 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
25-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %18 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
26-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %19 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
27-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %20 = call <vscale x 32 x i16> @llvm.experimental.stepvector.nxv32i16()
28-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %21 = call <vscale x 1 x i32> @llvm.experimental.stepvector.nxv1i32()
29-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %22 = call <vscale x 2 x i32> @llvm.experimental.stepvector.nxv2i32()
30-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %23 = call <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
31-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %24 = call <vscale x 8 x i32> @llvm.experimental.stepvector.nxv8i32()
32-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %25 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
33-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %26 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
34-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %27 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
35-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %28 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
36-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %29 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
37-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %30 = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
38-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %31 = call <vscale x 2 x i64> @llvm.experimental.stepvector.nxv2i64()
39-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %32 = call <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
40-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %33 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
41-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %34 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
42-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %35 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
43-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %36 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
44-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %37 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
45-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %38 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
46-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %39 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
47-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %40 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
48-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %41 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
49-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %42 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
50-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %43 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
51-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %44 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
11+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %5 = call <vscale x 16 x i8> @llvm.experimental.stepvector.nxv16i8()
12+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %6 = call <vscale x 32 x i8> @llvm.experimental.stepvector.nxv32i8()
13+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %7 = call <vscale x 64 x i8> @llvm.experimental.stepvector.nxv64i8()
14+
; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %8 = call <vscale x 128 x i8> @llvm.experimental.stepvector.nxv128i8()
15+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %9 = call <vscale x 1 x i16> @llvm.experimental.stepvector.nxv1i16()
16+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %10 = call <vscale x 2 x i16> @llvm.experimental.stepvector.nxv2i16()
17+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %11 = call <vscale x 4 x i16> @llvm.experimental.stepvector.nxv4i16()
18+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %12 = call <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
19+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %13 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
20+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %14 = call <vscale x 32 x i16> @llvm.experimental.stepvector.nxv32i16()
21+
; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %15 = call <vscale x 64 x i16> @llvm.experimental.stepvector.nxv64i16()
22+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %16 = call <vscale x 1 x i32> @llvm.experimental.stepvector.nxv1i32()
23+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %17 = call <vscale x 2 x i32> @llvm.experimental.stepvector.nxv2i32()
24+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %18 = call <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
25+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %19 = call <vscale x 8 x i32> @llvm.experimental.stepvector.nxv8i32()
26+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %20 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
27+
; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %21 = call <vscale x 32 x i32> @llvm.experimental.stepvector.nxv32i32()
28+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %22 = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
29+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %23 = call <vscale x 2 x i64> @llvm.experimental.stepvector.nxv2i64()
30+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %24 = call <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
31+
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %25 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
32+
; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %26 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
5233
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
5334
;
54-
%zero = call <vscale x 1 x i8> @llvm.experimental.stepvector.nxv1i8()
55-
%1 = call <vscale x 2 x i8> @llvm.experimental.stepvector.nxv2i8()
56-
%2 = call <vscale x 4 x i8> @llvm.experimental.stepvector.nxv4i8()
57-
%3 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
58-
%4 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
59-
%5 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
60-
%6 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
61-
%7 = call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
62-
%8 = call <vscale x 16 x i8> @llvm.experimental.stepvector.nxv16i8()
63-
%9 = call <vscale x 32 x i8> @llvm.experimental.stepvector.nxv32i8()
64-
%10 = call <vscale x 64 x i8> @llvm.experimental.stepvector.nxv64i8()
65-
%11 = call <vscale x 1 x i16> @llvm.experimental.stepvector.nxv1i16()
66-
%12 = call <vscale x 2 x i16> @llvm.experimental.stepvector.nxv2i16()
67-
%13 = call <vscale x 4 x i16> @llvm.experimental.stepvector.nxv4i16()
68-
%14 = call <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
69-
%15 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
70-
%16 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
71-
%17 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
72-
%18 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
73-
%19 = call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
74-
%20 = call <vscale x 32 x i16> @llvm.experimental.stepvector.nxv32i16()
75-
%21 = call <vscale x 1 x i32> @llvm.experimental.stepvector.nxv1i32()
76-
%22 = call <vscale x 2 x i32> @llvm.experimental.stepvector.nxv2i32()
77-
%23 = call <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
78-
%24 = call <vscale x 8 x i32> @llvm.experimental.stepvector.nxv8i32()
79-
%25 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
80-
%26 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
81-
%27 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
82-
%28 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
83-
%29 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
84-
%30 = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
85-
%31 = call <vscale x 2 x i64> @llvm.experimental.stepvector.nxv2i64()
86-
%32 = call <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
87-
%33 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
88-
%34 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
89-
%35 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
90-
%36 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
91-
%37 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
92-
%38 = call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
93-
%39 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
94-
%40 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
95-
%41 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
96-
%42 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
97-
%43 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
98-
%44 = call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
35+
call <vscale x 1 x i8> @llvm.experimental.stepvector.nxv1i8()
36+
call <vscale x 2 x i8> @llvm.experimental.stepvector.nxv2i8()
37+
call <vscale x 4 x i8> @llvm.experimental.stepvector.nxv4i8()
38+
call <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
39+
call <vscale x 16 x i8> @llvm.experimental.stepvector.nxv16i8()
40+
call <vscale x 32 x i8> @llvm.experimental.stepvector.nxv32i8()
41+
call <vscale x 64 x i8> @llvm.experimental.stepvector.nxv64i8()
42+
call <vscale x 128 x i8> @llvm.experimental.stepvector.nxv128i8()
43+
call <vscale x 1 x i16> @llvm.experimental.stepvector.nxv1i16()
44+
call <vscale x 2 x i16> @llvm.experimental.stepvector.nxv2i16()
45+
call <vscale x 4 x i16> @llvm.experimental.stepvector.nxv4i16()
46+
call <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
47+
call <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
48+
call <vscale x 32 x i16> @llvm.experimental.stepvector.nxv32i16()
49+
call <vscale x 64 x i16> @llvm.experimental.stepvector.nxv64i16()
50+
call <vscale x 1 x i32> @llvm.experimental.stepvector.nxv1i32()
51+
call <vscale x 2 x i32> @llvm.experimental.stepvector.nxv2i32()
52+
call <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
53+
call <vscale x 8 x i32> @llvm.experimental.stepvector.nxv8i32()
54+
call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
55+
call <vscale x 32 x i32> @llvm.experimental.stepvector.nxv32i32()
56+
call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
57+
call <vscale x 2 x i64> @llvm.experimental.stepvector.nxv2i64()
58+
call <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
59+
call <vscale x 8 x i64> @llvm.experimental.stepvector.nxv8i64()
60+
call <vscale x 16 x i64> @llvm.experimental.stepvector.nxv16i64()
9961
ret void
10062
}
10163

@@ -107,17 +69,20 @@ declare <vscale x 8 x i8> @llvm.experimental.stepvector.nxv8i8()
10769
declare <vscale x 16 x i8> @llvm.experimental.stepvector.nxv16i8()
10870
declare <vscale x 32 x i8> @llvm.experimental.stepvector.nxv32i8()
10971
declare <vscale x 64 x i8> @llvm.experimental.stepvector.nxv64i8()
72+
declare <vscale x 128 x i8> @llvm.experimental.stepvector.nxv128i8()
11073
declare <vscale x 1 x i16> @llvm.experimental.stepvector.nxv1i16()
11174
declare <vscale x 2 x i16> @llvm.experimental.stepvector.nxv2i16()
11275
declare <vscale x 4 x i16> @llvm.experimental.stepvector.nxv4i16()
11376
declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
11477
declare <vscale x 16 x i16> @llvm.experimental.stepvector.nxv16i16()
11578
declare <vscale x 32 x i16> @llvm.experimental.stepvector.nxv32i16()
79+
declare <vscale x 64 x i16> @llvm.experimental.stepvector.nxv64i16()
11680
declare <vscale x 1 x i32> @llvm.experimental.stepvector.nxv1i32()
11781
declare <vscale x 2 x i32> @llvm.experimental.stepvector.nxv2i32()
11882
declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
11983
declare <vscale x 8 x i32> @llvm.experimental.stepvector.nxv8i32()
12084
declare <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
85+
declare <vscale x 32 x i32> @llvm.experimental.stepvector.nxv32i32()
12186
declare <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
12287
declare <vscale x 2 x i64> @llvm.experimental.stepvector.nxv2i64()
12388
declare <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()

0 commit comments

Comments
 (0)