Skip to content

Commit 99a1ed1

Browse files
committed
[RISCV] Handle zvfhmin promotion to f32 in half arith costs
Arithmetic half ops on zvfhmin will be promoted and carried out in f32, so this updates getArithmeticInstrCost to check for this.
1 parent 89c10e2 commit 99a1ed1

File tree

2 files changed

+132
-63
lines changed

2 files changed

+132
-63
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,13 @@ InstructionCost RISCVTTIImpl::getArithmeticInstrCost(
18161816
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
18171817
Args, CxtI);
18181818

1819+
// On zvfhmin, f16 vectors may be promoted to f32.
1820+
// FIXME: nxv32f16 will be custom lowered and split.
1821+
unsigned ISDOpcode = TLI->InstructionOpcodeToISD(Opcode);
1822+
if (TLI->getOperationAction(ISDOpcode, LT.second) ==
1823+
TargetLoweringBase::LegalizeAction::Promote)
1824+
LT.second = TLI->getTypeToPromoteTo(ISDOpcode, LT.second);
1825+
18191826
auto getConstantMatCost =
18201827
[&](unsigned Operand, TTI::OperandValueInfo OpInfo) -> InstructionCost {
18211828
if (OpInfo.isUniform() && TLI->canSplatOperand(Opcode, Operand))
@@ -1837,7 +1844,7 @@ InstructionCost RISCVTTIImpl::getArithmeticInstrCost(
18371844
ConstantMatCost += getConstantMatCost(1, Op2Info);
18381845

18391846
unsigned Op;
1840-
switch (TLI->InstructionOpcodeToISD(Opcode)) {
1847+
switch (ISDOpcode) {
18411848
case ISD::ADD:
18421849
case ISD::SUB:
18431850
Op = RISCV::VADD_VV;
@@ -1867,11 +1874,9 @@ InstructionCost RISCVTTIImpl::getArithmeticInstrCost(
18671874
break;
18681875
case ISD::FADD:
18691876
case ISD::FSUB:
1870-
// TODO: Address FP16 with VFHMIN
18711877
Op = RISCV::VFADD_VV;
18721878
break;
18731879
case ISD::FMUL:
1874-
// TODO: Address FP16 with VFHMIN
18751880
Op = RISCV::VFMUL_VV;
18761881
break;
18771882
case ISD::FDIV:

0 commit comments

Comments
 (0)