[llvm] [DAG] computeKnownFPClass - add ISD::SINT_TO_FP/UINT_TO_FP handling (PR #190539)

Max Graey via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 7 18:25:06 PDT 2026


================
@@ -287,6 +287,73 @@ KnownFPClass KnownFPClass::bitcast(const fltSemantics &FltSemantics,
   return Known;
 }
 
+static KnownFPClass itofp_impl(const KnownBits &KnownSrc,
+                               const fltSemantics &FltSem,
+                               FPClassTest InterestedClasses, bool IsSigned) {
+  KnownFPClass Known;
+  // Cannot produce nan
+  Known.knownNot(fcNan);
+
+  // Integers cannot be subnormal
+  Known.knownNot(fcSubnormal);
+
+  // sitofp and uitofp turn into +0.0 for zero.
+  Known.knownNot(fcNegZero);
+
+  // UIToFP is always non-negative regardless of known bits.
+  if (!IsSigned)
+    Known.signBitMustBeZero();
+
+  // Only compute known bits if we can learn something useful from them.
+  if (!(InterestedClasses & (fcPosZero | fcNormal | fcInf)))
+    return Known;
+
+  // If the integer is non-zero, the result cannot be +0.0
+  if (KnownSrc.isNonZero())
+    Known.knownNot(fcPosZero);
+
+  if (IsSigned) {
+    // If the signed integer is known non-negative, the result is
+    // non-negative. If the signed integer is known negative, the result is
+    // negative.
+    if (KnownSrc.isNonNegative())
+      Known.signBitMustBeZero();
+    else if (KnownSrc.isNegative())
+      Known.signBitMustBeOne();
+  }
+
+  // Guard kept for ilogb()
----------------
MaxGraey wrote:

Comment not relevant to updated part of predicate

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


More information about the llvm-commits mailing list