@@ -1541,6 +1541,33 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
1541
1541
cast<VectorType>(ICA.getArgTypes ()[0 ]), {}, CostKind,
1542
1542
0 , cast<VectorType>(ICA.getReturnType ()));
1543
1543
}
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
+ }
1544
1571
}
1545
1572
1546
1573
if (ST->hasVInstructions () && RetTy->isVectorTy ()) {
0 commit comments