@@ -1497,6 +1497,33 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
1497
1497
cast<VectorType>(ICA.getArgTypes ()[0 ]), {}, CostKind,
1498
1498
0 , cast<VectorType>(ICA.getReturnType ()));
1499
1499
}
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
+ }
1500
1527
}
1501
1528
1502
1529
if (ST->hasVInstructions () && RetTy->isVectorTy ()) {
0 commit comments