Skip to content

Commit 203183e

Browse files
committed
[RISCV][TTI] Scale the cost of Select with LMUL
Use the Val type to estimate the instruction cost for SelectInst.
1 parent a77d3d9 commit 203183e

File tree

3 files changed

+64
-52
lines changed

3 files changed

+64
-52
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,10 +1317,14 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
13171317
// vmandn.mm v8, v8, v9
13181318
// vmand.mm v9, v0, v9
13191319
// vmor.mm v0, v9, v8
1320-
return LT.first * 3;
1320+
return LT.first *
1321+
getRISCVInstructionCost(
1322+
{RISCV::VMANDN_MM, RISCV::VMAND_MM, RISCV::VMOR_MM},
1323+
LT.second, CostKind);
13211324
}
13221325
// vselect and max/min are supported natively.
1323-
return LT.first * 1;
1326+
return LT.first *
1327+
getRISCVInstructionCost(RISCV::VMERGE_VVM, LT.second, CostKind);
13241328
}
13251329

13261330
if (ValTy->getScalarSizeInBits() == 1) {
@@ -1329,13 +1333,21 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
13291333
// vmandn.mm v8, v8, v9
13301334
// vmand.mm v9, v0, v9
13311335
// vmor.mm v0, v9, v8
1332-
return LT.first * 5;
1336+
MVT InterimVT = LT.second.changeVectorElementType(MVT::i8);
1337+
return LT.first *
1338+
getRISCVInstructionCost({RISCV::VMV_V_X, RISCV::VMSNE_VI},
1339+
InterimVT, CostKind) +
1340+
LT.first * getRISCVInstructionCost(
1341+
{RISCV::VMANDN_MM, RISCV::VMAND_MM, RISCV::VMOR_MM},
1342+
LT.second, CostKind);
13331343
}
13341344

13351345
// vmv.v.x v10, a0
13361346
// vmsne.vi v0, v10, 0
13371347
// vmerge.vvm v8, v9, v8, v0
1338-
return LT.first * 3;
1348+
return LT.first * getRISCVInstructionCost(
1349+
{RISCV::VMV_V_X, RISCV::VMSNE_VI, RISCV::VMERGE_VVM},
1350+
LT.second, CostKind);
13391351
}
13401352

13411353
if ((Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) &&

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33

44
define void @get_lane_mask() {
55
; CHECK-LABEL: 'get_lane_mask'
6-
; CHECK-NEXT: Cost Model: Found an estimated cost of 22 for instruction: %mask_nxv16i1_i64 = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 undef, i64 undef)
7-
; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %mask_nxv8i1_i64 = call <vscale x 8 x i1> @llvm.get.active.lane.mask.nxv8i1.i64(i64 undef, i64 undef)
8-
; CHECK-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %mask_nxv4i1_i64 = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 undef, i64 undef)
9-
; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %mask_nxv2i1_i64 = call <vscale x 2 x i1> @llvm.get.active.lane.mask.nxv2i1.i64(i64 undef, i64 undef)
6+
; CHECK-NEXT: Cost Model: Found an estimated cost of 36 for instruction: %mask_nxv16i1_i64 = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 undef, i64 undef)
7+
; CHECK-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %mask_nxv8i1_i64 = call <vscale x 8 x i1> @llvm.get.active.lane.mask.nxv8i1.i64(i64 undef, i64 undef)
8+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %mask_nxv4i1_i64 = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 undef, i64 undef)
9+
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %mask_nxv2i1_i64 = call <vscale x 2 x i1> @llvm.get.active.lane.mask.nxv2i1.i64(i64 undef, i64 undef)
1010
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %mask_nxv1i1_i64 = call <vscale x 1 x i1> @llvm.get.active.lane.mask.nxv1i1.i64(i64 undef, i64 undef)
11-
; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %mask_nxv16i1_i32 = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i32(i32 undef, i32 undef)
12-
; CHECK-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %mask_nxv8i1_i32 = call <vscale x 8 x i1> @llvm.get.active.lane.mask.nxv8i1.i32(i32 undef, i32 undef)
13-
; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %mask_nxv4i1_i32 = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i32(i32 undef, i32 undef)
11+
; CHECK-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %mask_nxv16i1_i32 = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i32(i32 undef, i32 undef)
12+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %mask_nxv8i1_i32 = call <vscale x 8 x i1> @llvm.get.active.lane.mask.nxv8i1.i32(i32 undef, i32 undef)
13+
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %mask_nxv4i1_i32 = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i32(i32 undef, i32 undef)
1414
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %mask_nxv2i1_i32 = call <vscale x 2 x i1> @llvm.get.active.lane.mask.nxv2i1.i32(i32 undef, i32 undef)
1515
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %mask_nxv1i1_i32 = call <vscale x 1 x i1> @llvm.get.active.lane.mask.nxv1i1.i32(i32 undef, i32 undef)
16-
; CHECK-NEXT: Cost Model: Found an estimated cost of 44 for instruction: %mask_nxv32i1_i64 = call <vscale x 32 x i1> @llvm.get.active.lane.mask.nxv32i1.i64(i64 undef, i64 undef)
17-
; CHECK-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %mask_nxv16i1_i16 = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i16(i16 undef, i16 undef)
18-
; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %mask_v16i1_i64 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 undef, i64 undef)
19-
; CHECK-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %mask_v8i1_i64 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 undef, i64 undef)
20-
; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %mask_v4i1_i64 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 undef, i64 undef)
16+
; CHECK-NEXT: Cost Model: Found an estimated cost of 72 for instruction: %mask_nxv32i1_i64 = call <vscale x 32 x i1> @llvm.get.active.lane.mask.nxv32i1.i64(i64 undef, i64 undef)
17+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %mask_nxv16i1_i16 = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i16(i16 undef, i16 undef)
18+
; CHECK-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %mask_v16i1_i64 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 undef, i64 undef)
19+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %mask_v8i1_i64 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 undef, i64 undef)
20+
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %mask_v4i1_i64 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 undef, i64 undef)
2121
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %mask_v2i1_i64 = call <2 x i1> @llvm.get.active.lane.mask.v2i1.i64(i64 undef, i64 undef)
22-
; CHECK-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %mask_v16i1_i32 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i32(i32 undef, i32 undef)
23-
; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %mask_v8i1_i32 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i32(i32 undef, i32 undef)
22+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %mask_v16i1_i32 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i32(i32 undef, i32 undef)
23+
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %mask_v8i1_i32 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i32(i32 undef, i32 undef)
2424
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %mask_v4i1_i32 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 undef, i32 undef)
2525
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %mask_v2i1_i32 = call <2 x i1> @llvm.get.active.lane.mask.v2i1.i32(i32 undef, i32 undef)
26-
; CHECK-NEXT: Cost Model: Found an estimated cost of 22 for instruction: %mask_v32i1_i64 = call <32 x i1> @llvm.get.active.lane.mask.v32i1.i64(i64 undef, i64 undef)
27-
; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %mask_v16i1_i16 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i16(i16 undef, i16 undef)
26+
; CHECK-NEXT: Cost Model: Found an estimated cost of 36 for instruction: %mask_v32i1_i64 = call <32 x i1> @llvm.get.active.lane.mask.v32i1.i64(i64 undef, i64 undef)
27+
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %mask_v16i1_i16 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i16(i16 undef, i16 undef)
2828
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
2929
;
3030
%mask_nxv16i1_i64 = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 undef, i64 undef)

0 commit comments

Comments
 (0)