[Bug middle-end/15945] New: Incorrect floating point optimization

jakub at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Jun 11 16:43:00 GMT 2004


The following testcase is miscompiled with gcc-3_4-branch at -O3 on
s390x-redhat-linux (worked properly in GCC 3.3.x and earlier).

/* { dg-do run { target *-*-linux* } } */
/* { dg-options "-O3 -lm" } */

#include <fenv.h>
#include <stdlib.h>

typedef union
{
  int i[2];
  double x;
} U;

double __attribute__ ((noinline))
foo (double x)
{
  U u, v;

  u.x = x;
  u.i[0] = 0x7ff00000;
  v.i[0] = 0x7ff00000;
  u.i[1] = 0;
  v.i[1] = 0;
  return u.x / v.x;
}

double d;

int
main (void)
{
  feclearexcept (FE_ALL_EXCEPT);
  d = foo (2.0);
  if (fetestexcept (FE_INVALID) == 0)
    abort ();
  return 0;
}

Unless -ffast-math, the division should not be optimized out, as it is supposed
to generate invalid exception.
This causes miscompilation of glibc.

-- 
           Summary: Incorrect floating point optimization
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: s390x-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15945



More information about the Gcc-bugs mailing list