https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126547

            Bug ID: 126547
           Summary: [16/17 Regression] Wrong code with ranger and FP
                    division and infinities
           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: ---

int printf (const char *, ...);

/* a1 / a2 == +Inf does not imply that a2 is a zero: the quotient overflows to
   +Inf for every a2 small enough, so the reverse range of the divisor has to
   include the subnormals.  Ranger derives [-0.0, +0.0] for a2 on the true
   edge and the jump threader then folds "a2 > 0.0" to false there.  */

__attribute__((noipa)) static int
f (unsigned int p, long double a2)
{
  long double a1 = (long double) (int) (p & 7) + 1.0L;  /* [1.0, 8.0] */
  long double d = a1 / a2;
  int n = 0;
  if (d >= __builtin_infl ())
    n += 1;
  if (a2 > 0.0L)
    n += 2;
  return n;
}

int
main (void)
{
  int r = f (0, __LDBL_DENORM_MIN__);   /* 1.0L / 6.5e-4966L == +Inf */
  printf ("%d\n", r);
  if (r != 3)
    __builtin_abort ();
  return 0;
}

aborts at -O2 and passes at -O0

Reply via email to