[llvm] [TTI] Check type legalization of both src and result for fpto{u|s}i.sat. (PR #147657)

Elvis Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 10 00:22:22 PDT 2025


================
@@ -2486,11 +2486,18 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
       ISD = ISD::UMULO;
       break;
     case Intrinsic::fptosi_sat:
-      ISD = ISD::FP_TO_SINT_SAT;
-      break;
-    case Intrinsic::fptoui_sat:
-      ISD = ISD::FP_TO_UINT_SAT;
+    case Intrinsic::fptoui_sat: {
+      std::pair<InstructionCost, MVT> SrcLT = getTypeLegalizationCost(Tys[0]);
+      std::pair<InstructionCost, MVT> RetLT = getTypeLegalizationCost(RetTy);
+
+      // For cast instructions, types are different between source and
+      // destination. Also need to check if the source type can be legalize.
----------------
ElvisWang123 wrote:

Some of the vector type might not be legalize if the target not support.

For example, `fptoui.sat(<vscale x 1 x double> ...)` is illegal type under `riscv64, +zve32f` (target only support f32 vectors no f64 vector support) and  cannot be scalarize  since the element counts is unknown  at compile time.  So the cost of `fptoui.sat(<vscale x 1 x double> ...)` should be invalid.

https://github.com/llvm/llvm-project/pull/147657


More information about the llvm-commits mailing list