Skip to content

Commit 5a500d9

Browse files
committed
[RISCV][TTI] Implement cost for llvm.fpto{u|s}i.sat.
1 parent 9916a5c commit 5a500d9

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
@@ -1497,6 +1497,33 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
14971497
cast<VectorType>(ICA.getArgTypes()[0]), {}, CostKind,
14981498
0, cast<VectorType>(ICA.getReturnType()));
14991499
}
1500+
case Intrinsic::fptoui_sat:
1501+
case Intrinsic::fptosi_sat: {
1502+
InstructionCost Cost = 0;
1503+
bool IsSigned = ICA.getID() == Intrinsic::fptosi_sat;
1504+
Type *SrcTy = ICA.getArgTypes()[0];
1505+
1506+
auto SrcLT = getTypeLegalizationCost(SrcTy);
1507+
auto DstLT = getTypeLegalizationCost(RetTy);
1508+
if (!SrcLT.first.isValid() || !DstLT.first.isValid())
1509+
return InstructionCost::getInvalid();
1510+
1511+
IntrinsicCostAttributes Attrs1(Intrinsic::minnum, SrcTy, {SrcTy, SrcTy});
1512+
Cost += getIntrinsicInstrCost(Attrs1, CostKind);
1513+
IntrinsicCostAttributes Attrs2(Intrinsic::maxnum, SrcTy, {SrcTy, SrcTy});
1514+
Cost += getIntrinsicInstrCost(Attrs2, CostKind);
1515+
Cost +=
1516+
getCastInstrCost(IsSigned ? Instruction::FPToSI : Instruction::FPToUI,
1517+
RetTy, SrcTy, TTI::CastContextHint::None, CostKind);
1518+
if (IsSigned) {
1519+
Type *CondTy = RetTy->getWithNewBitWidth(1);
1520+
Cost += getCmpSelInstrCost(BinaryOperator::FCmp, SrcTy, CondTy,
1521+
CmpInst::FCMP_UNO, CostKind);
1522+
Cost += getCmpSelInstrCost(BinaryOperator::Select, RetTy, CondTy,
1523+
CmpInst::FCMP_UNO, CostKind);
1524+
}
1525+
return Cost;
1526+
}
15001527
}
15011528

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

0 commit comments

Comments
 (0)