Skip to content

Commit a43aa2b

Browse files
committed
[RISCV][TTI] Implement cost for llvm.fpto{u|s}i.sat.
1 parent 7016897 commit a43aa2b

File tree

2 files changed

+367
-340
lines changed

2 files changed

+367
-340
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,33 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
15411541
cast<VectorType>(ICA.getArgTypes()[0]), {}, CostKind,
15421542
0, cast<VectorType>(ICA.getReturnType()));
15431543
}
1544+
case Intrinsic::fptoui_sat:
1545+
case Intrinsic::fptosi_sat: {
1546+
InstructionCost Cost = 0;
1547+
bool IsSigned = ICA.getID() == Intrinsic::fptosi_sat;
1548+
Type *SrcTy = ICA.getArgTypes()[0];
1549+
1550+
auto SrcLT = getTypeLegalizationCost(SrcTy);
1551+
auto DstLT = getTypeLegalizationCost(RetTy);
1552+
if (!SrcLT.first.isValid() || !DstLT.first.isValid())
1553+
return InstructionCost::getInvalid();
1554+
1555+
IntrinsicCostAttributes Attrs1(Intrinsic::minnum, SrcTy, {SrcTy, SrcTy});
1556+
Cost += getIntrinsicInstrCost(Attrs1, CostKind);
1557+
IntrinsicCostAttributes Attrs2(Intrinsic::maxnum, SrcTy, {SrcTy, SrcTy});
1558+
Cost += getIntrinsicInstrCost(Attrs2, CostKind);
1559+
Cost +=
1560+
getCastInstrCost(IsSigned ? Instruction::FPToSI : Instruction::FPToUI,
1561+
RetTy, SrcTy, TTI::CastContextHint::None, CostKind);
1562+
if (IsSigned) {
1563+
Type *CondTy = RetTy->getWithNewBitWidth(1);
1564+
Cost += getCmpSelInstrCost(BinaryOperator::FCmp, SrcTy, CondTy,
1565+
CmpInst::FCMP_UNO, CostKind);
1566+
Cost += getCmpSelInstrCost(BinaryOperator::Select, RetTy, CondTy,
1567+
CmpInst::FCMP_UNO, CostKind);
1568+
}
1569+
return Cost;
1570+
}
15441571
}
15451572

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

0 commit comments

Comments
 (0)