[Bug tree-optimization/126534] New: [14/15/16/17 Regression] Wrong code with ranger and sqrt

"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=126534

            Bug ID: 126534
           Summary: [14/15/16/17 Regression] Wrong code with ranger and
                    sqrt
           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: ---

/* cfn_sqrt::op1_range squares the bound of the result without allowing for
   the half ulp that correct rounding of sqrt absorbs.
   __builtin_sqrt (25.000000000000004) == 5.0 and
   __builtin_sqrt (24.999999999999996) == 5.0, so both neighbours of 25.0
   reach the edge that the reverse range restricts to 25.0.  */

__attribute__((noipa)) int
f (double x)
{
  double y = __builtin_sqrt (x);
  if (y <= 5.0)
    {
      if (x > 25.0)
        return 1;
      return 2;
    }
  return 3;
}

__attribute__((noipa)) int
g (double x)
{
  double y = __builtin_sqrt (x);
  if (y >= 5.0)
    {
      if (x < 25.0)
        return 1;
      return 2;
    }
  return 3;
}

int
main (void)
{
  if (f (0x1.9000000000001p+4) != 1)    /* 25.000000000000004 */
    __builtin_abort ();
  if (g (0x1.8ffffffffffffp+4) != 1)    /* 24.999999999999996 */
    __builtin_abort ();
  return 0;
}

Aborts at -O2 -lm and passes at -O0 (on aarch64)
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.