Skip to content

Commit 4a35655

Browse files
committed
[RISCV][TTI] Factor out getVSlideCost helper [nfc]
Reasonable implementations may differ in complexity cost, so doing some API prepwork to support tunables. Note that this patch only covers the cases where we model the slide cost as linear. A separate patch will propose changing our insert and extract costs from constant-in-lmul to linear-in-lmul.
1 parent f346cbd commit 4a35655

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ InstructionCost RISCVTTIImpl::getVRGatherVICost(MVT VT) {
277277
return getLMULCost(VT);
278278
}
279279

280+
/// Return the cost of a vslidedown.vi/vx or vslideup.vi/vx instruction
281+
/// for the type VT. (This does not cover the vslide1up or vslide1down
282+
/// variants.) Slides may be linear in the number of vregs implied by LMUL,
283+
/// or may track the vrgather.vv cost. It is implementation-dependent.
284+
InstructionCost RISCVTTIImpl::getVSlideCost(MVT VT) {
285+
return getLMULCost(VT);
286+
}
287+
280288
InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
281289
VectorType *Tp, ArrayRef<int> Mask,
282290
TTI::TargetCostKind CostKind,
@@ -397,12 +405,12 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
397405
// Example sequence:
398406
// vsetivli zero, 4, e8, mf2, tu, ma (ignored)
399407
// vslidedown.vi v8, v9, 2
400-
return LT.first * getLMULCost(LT.second);
408+
return LT.first * getVSlideCost(LT.second);
401409
case TTI::SK_InsertSubvector:
402410
// Example sequence:
403411
// vsetivli zero, 4, e8, mf2, tu, ma (ignored)
404412
// vslideup.vi v8, v9, 2
405-
return LT.first * getLMULCost(LT.second);
413+
return LT.first * getVSlideCost(LT.second);
406414
case TTI::SK_Select: {
407415
// Example sequence:
408416
// li a0, 90
@@ -449,7 +457,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
449457
// vslidedown+vslideup.
450458
// TODO: Multiplying by LT.first implies this legalizes into multiple copies
451459
// of similar code, but I think we expand through memory.
452-
return 2 * LT.first * getLMULCost(LT.second);
460+
return 2 * LT.first * getVSlideCost(LT.second);
453461
case TTI::SK_Reverse: {
454462
// TODO: Cases to improve here:
455463
// * Illegal vector types

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
125125

126126
InstructionCost getVRGatherVVCost(MVT VT);
127127
InstructionCost getVRGatherVICost(MVT VT);
128+
InstructionCost getVSlideCost(MVT VT);
128129

129130
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp,
130131
ArrayRef<int> Mask,

0 commit comments

Comments
 (0)