@@ -1489,6 +1489,34 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
1489
1489
cast<VectorType>(ICA.getArgTypes ()[0 ]), {}, CostKind,
1490
1490
0 , cast<VectorType>(ICA.getReturnType ()));
1491
1491
}
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
+ }
1492
1520
}
1493
1521
1494
1522
if (ST->hasVInstructions () && RetTy->isVectorTy ()) {
0 commit comments