[Bug tree-optimization/126549] New: [16/17 Regression] Wrong code with ranger and int->float casts

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

            Bug ID: 126549
           Summary: [16/17 Regression] Wrong code with ranger and
                    int->float casts
           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: ---

/* operator_cast::fold_range (frange, tree, const irange &): the forward
   INT -> FLOAT cast.  It computes the bounds with real_from_integer in the
   destination mode, which correctly overflows to +Inf for _Float16, and then
   throws that away with frange_drop_infs, so the range of (_Float16) u for
   u in [0, 100000] comes out as [0, 65504] and the comparison h > 65504.0f16
   folds to 0.  For u = 70000 the real value is +Inf.  */
__attribute__((noipa)) int
g (unsigned a)
{
  unsigned u = a % 100001u;        /* u in [0, 100000] */
  _Float16 h = (_Float16) u;
  return h > 65504.0f16;
}

int
main (void)
{
  volatile unsigned v = 70000u;
  if (g (v) != 1)
    __builtin_abort ();
  return 0;
}

aborts on aarch64 at -O2 and passes at -O0
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.