[llvm] [KnownFPClass] Correct denormal handling for `KnownFPClass::roundToIntegral` (PR #219700)

Eric Ross via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 16:09:54 PDT 2026


================
@@ -1593,16 +1593,26 @@ void GISelValueTracking::computeKnownFPClass(Register R,
     Register Val = MI.getOperand(1).getReg();
     KnownFPClass KnownSrc;
     FPClassTest InterestedSrcs = InterestedClasses;
-    if (InterestedSrcs & fcPosFinite)
-      InterestedSrcs |= fcPosFinite;
+
+    // Negative round ups towards zero produce negative zero.
     if (InterestedSrcs & fcNegFinite)
       InterestedSrcs |= fcNegFinite;
+
+    // Negative subnormals may flush to positive zero.
+    if (InterestedSrcs & fcPosFinite)
+      InterestedSrcs |= fcPosFinite | fcNegSubnormal;
+
     computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc, Depth + 1);
 
-    // TODO: handle multi unit FPTypes once LLT FPInfo lands
-    bool IsTrunc = Opcode == TargetOpcode::G_INTRINSIC_TRUNC;
+    LLT Ty = MRI.getType(Val).getScalarType();
+    const fltSemantics &FltSem = getFltSemanticForLLT(Ty);
+    DenormalMode Mode = MF->getDenormalMode(FltSem);
+    const bool IsKnownNeverMultiUnitFPType =
+        &FltSem != &APFloat::PPCDoubleDouble();
+
+    const bool IsTrunc = Opcode == TargetOpcode::G_INTRINSIC_TRUNC;
     Known = KnownFPClass::roundToIntegral(KnownSrc, IsTrunc,
-                                          /*IsMultiUnitFPType=*/false);
+                                          IsKnownNeverMultiUnitFPType, Mode);
----------------
ZERICO2005 wrote:


Additionally, the other reason for using `IsKnownNeverMultiUnitFPType` instead of `IsMultiUnitFPType` is for when we cannot determine the type (prior to the LTT type info stuff). `IsKnownNeverMultiUnitFPType` self documents what we should pass in to avoid making incorrect deductions when we cannot determine the input type.


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


More information about the llvm-commits mailing list