Skip to content

Commit 9c39d9b

Browse files
authored
Revert "[RISCV][CostModel] Add getRISCVInstructionCost() to TTI for Cost… (#73651)" (#76536)
Fails on bots https://lab.llvm.org/buildbot/#/builders/5/builds/39629 Issue #76535 This reverts commit 3e75dec.
1 parent 37f9036 commit 9c39d9b

13 files changed

+16
-725
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,19 +2711,11 @@ InstructionCost RISCVTargetLowering::getVRGatherVICost(MVT VT) const {
27112711
return getLMULCost(VT);
27122712
}
27132713

2714-
/// Return the cost of a vslidedown.vx or vslideup.vx instruction
2714+
/// Return the cost of a vslidedown.vi/vx or vslideup.vi/vx instruction
27152715
/// for the type VT. (This does not cover the vslide1up or vslide1down
27162716
/// variants.) Slides may be linear in the number of vregs implied by LMUL,
27172717
/// or may track the vrgather.vv cost. It is implementation-dependent.
2718-
InstructionCost RISCVTargetLowering::getVSlideVXCost(MVT VT) const {
2719-
return getLMULCost(VT);
2720-
}
2721-
2722-
/// Return the cost of a vslidedown.vi or vslideup.vi instruction
2723-
/// for the type VT. (This does not cover the vslide1up or vslide1down
2724-
/// variants.) Slides may be linear in the number of vregs implied by LMUL,
2725-
/// or may track the vrgather.vv cost. It is implementation-dependent.
2726-
InstructionCost RISCVTargetLowering::getVSlideVICost(MVT VT) const {
2718+
InstructionCost RISCVTargetLowering::getVSlideCost(MVT VT) const {
27272719
return getLMULCost(VT);
27282720
}
27292721

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ class RISCVTargetLowering : public TargetLowering {
526526

527527
InstructionCost getVRGatherVVCost(MVT VT) const;
528528
InstructionCost getVRGatherVICost(MVT VT) const;
529-
InstructionCost getVSlideVXCost(MVT VT) const;
530-
InstructionCost getVSlideVICost(MVT VT) const;
529+
InstructionCost getVSlideCost(MVT VT) const;
531530

532531
// Provide custom lowering hooks for some operations.
533532
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 13 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -34,65 +34,6 @@ static cl::opt<unsigned> SLPMaxVF(
3434
"exclusively by SLP vectorizer."),
3535
cl::Hidden);
3636

37-
InstructionCost
38-
RISCVTTIImpl::getRISCVInstructionCost(ArrayRef<unsigned> OpCodes, MVT VT,
39-
TTI::TargetCostKind CostKind) {
40-
size_t NumInstr = OpCodes.size();
41-
if (CostKind == TTI::TCK_CodeSize)
42-
return NumInstr;
43-
InstructionCost LMULCost = TLI->getLMULCost(VT);
44-
if ((CostKind != TTI::TCK_RecipThroughput) && (CostKind != TTI::TCK_Latency))
45-
return LMULCost * NumInstr;
46-
InstructionCost Cost = 0;
47-
for (auto Op : OpCodes) {
48-
switch (Op) {
49-
case RISCV::VRGATHER_VI:
50-
Cost += TLI->getVRGatherVICost(VT);
51-
break;
52-
case RISCV::VRGATHER_VV:
53-
Cost += TLI->getVRGatherVVCost(VT);
54-
break;
55-
case RISCV::VSLIDEUP_VI:
56-
case RISCV::VSLIDEDOWN_VI:
57-
Cost += TLI->getVSlideVICost(VT);
58-
break;
59-
case RISCV::VSLIDEUP_VX:
60-
case RISCV::VSLIDEDOWN_VX:
61-
Cost += TLI->getVSlideVXCost(VT);
62-
break;
63-
case RISCV::VREDMAX_VS:
64-
case RISCV::VREDMIN_VS:
65-
case RISCV::VREDMAXU_VS:
66-
case RISCV::VREDMINU_VS:
67-
case RISCV::VREDSUM_VS:
68-
case RISCV::VREDAND_VS:
69-
case RISCV::VREDOR_VS:
70-
case RISCV::VREDXOR_VS:
71-
case RISCV::VFREDMAX_VS:
72-
case RISCV::VFREDMIN_VS:
73-
case RISCV::VFREDUSUM_VS: {
74-
unsigned VL = VT.getVectorMinNumElements();
75-
if (!VT.isFixedLengthVector())
76-
VL *= *getVScaleForTuning();
77-
Cost += Log2_32_Ceil(VL);
78-
break;
79-
}
80-
case RISCV::VFREDOSUM_VS: {
81-
unsigned VL = VT.getVectorMinNumElements();
82-
if (!VT.isFixedLengthVector())
83-
VL *= *getVScaleForTuning();
84-
Cost += VL;
85-
break;
86-
}
87-
case RISCV::VMV_S_X:
88-
// FIXME: VMV_S_X doesn't use LMUL, the cost should be 1
89-
default:
90-
Cost += LMULCost;
91-
}
92-
}
93-
return Cost;
94-
}
95-
9637
InstructionCost RISCVTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty,
9738
TTI::TargetCostKind CostKind) {
9839
assert(Ty->isIntegerTy() &&
@@ -340,8 +281,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
340281
// Example sequence:
341282
// vnsrl.wi v10, v8, 0
342283
if (equal(DeinterleaveMask, Mask))
343-
return LT.first * getRISCVInstructionCost(RISCV::VNSRL_WI,
344-
LT.second, CostKind);
284+
return LT.first * TLI->getLMULCost(LT.second);
345285
}
346286
}
347287
}
@@ -352,8 +292,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
352292
LT.second.getVectorNumElements() <= 256)) {
353293
VectorType *IdxTy = getVRGatherIndexType(LT.second, *ST, Tp->getContext());
354294
InstructionCost IndexCost = getConstantPoolLoadCost(IdxTy, CostKind);
355-
return IndexCost +
356-
getRISCVInstructionCost(RISCV::VRGATHER_VV, LT.second, CostKind);
295+
return IndexCost + TLI->getVRGatherVVCost(LT.second);
357296
}
358297
[[fallthrough]];
359298
}
@@ -371,10 +310,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
371310
VectorType *MaskTy = VectorType::get(IntegerType::getInt1Ty(C), EC);
372311
InstructionCost IndexCost = getConstantPoolLoadCost(IdxTy, CostKind);
373312
InstructionCost MaskCost = getConstantPoolLoadCost(MaskTy, CostKind);
374-
return 2 * IndexCost +
375-
getRISCVInstructionCost({RISCV::VRGATHER_VV, RISCV::VRGATHER_VV},
376-
LT.second, CostKind) +
377-
MaskCost;
313+
return 2 * IndexCost + 2 * TLI->getVRGatherVVCost(LT.second) + MaskCost;
378314
}
379315
[[fallthrough]];
380316
}
@@ -429,24 +365,19 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
429365
// Example sequence:
430366
// vsetivli zero, 4, e8, mf2, tu, ma (ignored)
431367
// vslidedown.vi v8, v9, 2
432-
return LT.first *
433-
getRISCVInstructionCost(RISCV::VSLIDEDOWN_VI, LT.second, CostKind);
368+
return LT.first * TLI->getVSlideCost(LT.second);
434369
case TTI::SK_InsertSubvector:
435370
// Example sequence:
436371
// vsetivli zero, 4, e8, mf2, tu, ma (ignored)
437372
// vslideup.vi v8, v9, 2
438-
return LT.first *
439-
getRISCVInstructionCost(RISCV::VSLIDEUP_VI, LT.second, CostKind);
373+
return LT.first * TLI->getVSlideCost(LT.second);
440374
case TTI::SK_Select: {
441375
// Example sequence:
442376
// li a0, 90
443377
// vsetivli zero, 8, e8, mf2, ta, ma (ignored)
444378
// vmv.s.x v0, a0
445379
// vmerge.vvm v8, v9, v8, v0
446-
return LT.first *
447-
(TLI->getLMULCost(LT.second) + // FIXME: should be 1 for li
448-
getRISCVInstructionCost({RISCV::VMV_S_X, RISCV::VMERGE_VVM},
449-
LT.second, CostKind));
380+
return LT.first * 3 * TLI->getLMULCost(LT.second);
450381
}
451382
case TTI::SK_Broadcast: {
452383
bool HasScalar = (Args.size() > 0) && (Operator::getOpcode(Args[0]) ==
@@ -458,10 +389,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
458389
// vsetivli zero, 2, e8, mf8, ta, ma (ignored)
459390
// vmv.v.x v8, a0
460391
// vmsne.vi v0, v8, 0
461-
return LT.first *
462-
(TLI->getLMULCost(LT.second) + // FIXME: should be 1 for andi
463-
getRISCVInstructionCost({RISCV::VMV_V_X, RISCV::VMSNE_VI},
464-
LT.second, CostKind));
392+
return LT.first * TLI->getLMULCost(LT.second) * 3;
465393
}
466394
// Example sequence:
467395
// vsetivli zero, 2, e8, mf8, ta, mu (ignored)
@@ -472,40 +400,24 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
472400
// vmv.v.x v8, a0
473401
// vmsne.vi v0, v8, 0
474402

475-
return LT.first *
476-
(TLI->getLMULCost(LT.second) + // FIXME: this should be 1 for andi
477-
TLI->getLMULCost(
478-
LT.second) + // FIXME: vmv.x.s is the same as extractelement
479-
getRISCVInstructionCost({RISCV::VMV_V_I, RISCV::VMERGE_VIM,
480-
RISCV::VMV_V_X, RISCV::VMSNE_VI},
481-
LT.second, CostKind));
403+
return LT.first * TLI->getLMULCost(LT.second) * 6;
482404
}
483405

484406
if (HasScalar) {
485407
// Example sequence:
486408
// vmv.v.x v8, a0
487-
return LT.first *
488-
getRISCVInstructionCost(RISCV::VMV_V_X, LT.second, CostKind);
409+
return LT.first * TLI->getLMULCost(LT.second);
489410
}
490411

491412
// Example sequence:
492413
// vrgather.vi v9, v8, 0
493-
return LT.first *
494-
getRISCVInstructionCost(RISCV::VRGATHER_VI, LT.second, CostKind);
414+
return LT.first * TLI->getVRGatherVICost(LT.second);
495415
}
496-
case TTI::SK_Splice: {
416+
case TTI::SK_Splice:
497417
// vslidedown+vslideup.
498418
// TODO: Multiplying by LT.first implies this legalizes into multiple copies
499419
// of similar code, but I think we expand through memory.
500-
ArrayRef<unsigned> Opcodes;
501-
if (Index >= 0 && Index < 32)
502-
Opcodes = {RISCV::VSLIDEDOWN_VI, RISCV::VSLIDEUP_VX};
503-
else if (Index < 0 && Index > -32)
504-
Opcodes = {RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VI};
505-
else
506-
Opcodes = {RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VX};
507-
return LT.first * getRISCVInstructionCost(Opcodes, LT.second, CostKind);
508-
}
420+
return 2 * LT.first * TLI->getVSlideCost(LT.second);
509421
case TTI::SK_Reverse: {
510422
// TODO: Cases to improve here:
511423
// * Illegal vector types
@@ -525,9 +437,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
525437
if (LT.second.isFixedLengthVector())
526438
// vrsub.vi has a 5 bit immediate field, otherwise an li suffices
527439
LenCost = isInt<5>(LT.second.getVectorNumElements() - 1) ? 0 : 1;
528-
// FIXME: replace the constant `2` below with cost of {VID_V,VRSUB_VX}
529-
InstructionCost GatherCost =
530-
2 + getRISCVInstructionCost(RISCV::VRGATHER_VV, LT.second, CostKind);
440+
InstructionCost GatherCost = 2 + TLI->getVRGatherVVCost(LT.second);
531441
// Mask operation additionally required extend and truncate
532442
InstructionCost ExtendCost = Tp->getElementType()->isIntegerTy(1) ? 3 : 0;
533443
return LT.first * (LenCost + GatherCost + ExtendCost);

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
4848
/// actual target hardware.
4949
unsigned getEstimatedVLFor(VectorType *Ty);
5050

51-
InstructionCost getRISCVInstructionCost(ArrayRef<unsigned> OpCodes, MVT VT,
52-
TTI::TargetCostKind CostKind);
53-
5451
/// Return the cost of accessing a constant pool entry of the specified
5552
/// type.
5653
InstructionCost getConstantPoolLoadCost(Type *Ty,

0 commit comments

Comments
 (0)