[Bug tree-optimization/126464] New: [16/17 Regression] wrong code with FP ranges

"ktkachov at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126464

            Bug ID: 126464
           Summary: [16/17 Regression] wrong code with FP ranges
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

__attribute__((noipa)) double
scale (double x)
{
  float y = (float) x;

  if (y == -__builtin_inf ())
    return x * 0.5;           /* retry at half scale */
  return y;
}

/* Same shape, widening the other way, to show it is not _Float16 or float
   specific.  */
__attribute__((noipa)) long double
scale2 (long double x)
{
  double y = (double) x;

  if (y == __builtin_inf ())
    return x * 0.5L;
  return y;
}

int
main (void)
{
  if (scale (-1e300) != -5e299)
    __builtin_abort ();

  if (sizeof (long double) > sizeof (double)
      && scale2 (1e4000L) != 5e3999L)
    __builtin_abort ();

  return 0;
}

runs fine at -O0 and aborts at -O1 and above. Also with GCC 15 it works fine.
I think something to do with fp ranges
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.