Skip to content

Commit 324773e

Browse files
authored
[RISCV][TTI] Implement vector costs for llvm.fpto{u|s}i.sat(). (#143655)
This patch implement vector costs for `llvm.fptoui.sat()` in RISCV TTI.
1 parent 9285852 commit 324773e

File tree

2 files changed

+332
-304
lines changed

2 files changed

+332
-304
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,34 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
14891489
cast<VectorType>(ICA.getArgTypes()[0]), {}, CostKind,
14901490
0, cast<VectorType>(ICA.getReturnType()));
14911491
}
1492+
case Intrinsic::fptoui_sat:
1493+
case Intrinsic::fptosi_sat: {
1494+
InstructionCost Cost = 0;
1495+
bool IsSigned = ICA.getID() == Intrinsic::fptosi_sat;
1496+
Type *SrcTy = ICA.getArgTypes()[0];
1497+
1498+
auto SrcLT = getTypeLegalizationCost(SrcTy);
1499+
auto DstLT = getTypeLegalizationCost(RetTy);
1500+
if (!SrcTy->isVectorTy())
1501+
break;
1502+
1503+
if (!SrcLT.first.isValid() || !DstLT.first.isValid())
1504+
return InstructionCost::getInvalid();
1505+
1506+
Cost +=
1507+
getCastInstrCost(IsSigned ? Instruction::FPToSI : Instruction::FPToUI,
1508+
RetTy, SrcTy, TTI::CastContextHint::None, CostKind);
1509+
1510+
// Handle NaN.
1511+
// vmfne v0, v8, v8 # If v8[i] is NaN set v0[i] to 1.
1512+
// vmerge.vim v8, v8, 0, v0 # Convert NaN to 0.
1513+
Type *CondTy = RetTy->getWithNewBitWidth(1);
1514+
Cost += getCmpSelInstrCost(BinaryOperator::FCmp, SrcTy, CondTy,
1515+
CmpInst::FCMP_UNO, CostKind);
1516+
Cost += getCmpSelInstrCost(BinaryOperator::Select, RetTy, CondTy,
1517+
CmpInst::FCMP_UNO, CostKind);
1518+
return Cost;
1519+
}
14921520
}
14931521

14941522
if (ST->hasVInstructions() && RetTy->isVectorTy()) {

0 commit comments

Comments
 (0)