> In gnu/gcc/gcc/config/m88k/m88k.c, legitimize_operand() shortens
> double constants to single precision without checking that their
> values are preserved:
> 
> ```
>       if (exponent != 0x7ff /* NaN */
>         && l[1] == 0 /* Mantissa fits */
>         && ((exponent >> 7) == 0x8
>             || (exponent >> 7) == 0x7) /* Exponent fits */
>         && (temp = simplify_unary_operation (FLOAT_TRUNCATE, SFmode,
>                                              op, mode)) != 0)
>       return gen_rtx_FLOAT_EXTEND (mode, force_reg (SFmode, temp));
> ```
> 
> In this case, it accepts 0x1p128 even though conversion to
> single precision produces infinity.
> 
> A suggested fix is to shorten a finite double constant only when
> it can be represented exactly in the target single-precision format,
> including the sign of zero. Otherwise, keep the operand in double
> precision.

Good catch! The following diff ought to fix this, I'll be testing it
shortly.

Index: gnu/gcc/gcc/config/m88k/m88k.c
===================================================================
RCS file: /cvs/src/gnu/gcc/gcc/config/m88k/m88k.c,v
diff -u -p -r1.41 m88k.c
--- gnu/gcc/gcc/config/m88k/m88k.c      21 Oct 2025 18:35:35 -0000      1.41
+++ gnu/gcc/gcc/config/m88k/m88k.c      7 Nov 2026 16:06:16 -0000
@@ -964,8 +964,6 @@ legitimize_operand (rtx op, enum machine
 {
   rtx temp;
   REAL_VALUE_TYPE d;
-  long l[2];
-  int exponent;
 
   if (REG_P (op) || mode != DFmode)
     return op;
@@ -973,12 +971,8 @@ legitimize_operand (rtx op, enum machine
   if (GET_CODE (op) == CONST_DOUBLE)
     {
       REAL_VALUE_FROM_CONST_DOUBLE (d, op);
-      REAL_VALUE_TO_TARGET_DOUBLE (d, l);
-      exponent = (l[0] >> 20) & 0x7ff; /* not sign-extended */
-      if (exponent != 0x7ff /* NaN */
-         && l[1] == 0 /* Mantissa fits */
-         && ((exponent >> 7) == 0x8
-             || (exponent >> 7) == 0x7) /* Exponent fits */
+
+      if (exact_real_truncate (SFmode, &d)
          && (temp = simplify_unary_operation (FLOAT_TRUNCATE, SFmode,
                                               op, mode)) != 0)
        return gen_rtx_FLOAT_EXTEND (mode, force_reg (SFmode, temp));

Reply via email to