Bug 15945 - [3.4/4.0 Regression] Incorrect floating point optimization
Summary: [3.4/4.0 Regression] Incorrect floating point optimization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.4.1
Assignee: Not yet assigned to anyone
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2004-06-11 16:43 UTC by Jakub Jelinek
Modified: 2004-09-13 14:15 UTC (History)
1 user (show)

See Also:
Host:
Target: s390x-redhat-linux
Build:
Known to work: 3.3.3
Known to fail: 3.4.0
Last reconfirmed: 2004-06-11 21:47:44


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2004-06-11 16:43:28 UTC
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.
Comment 1 Andrew Pinski 2004-06-11 21:47:43 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-06/msg00767.html>.
Comment 2 GCC Commits 2004-06-14 17:45:20 UTC
Subject: Bug 15945

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2004-06-14 17:45:09

Modified files:
	gcc            : ChangeLog simplify-rtx.c 

Log message:
	PR middle-end/15945
	* simplify-rtx.c (simplify_binary_operation): Don't optimize out
	Inf + -Inf, Inf - Inf, Inf / Inf and 0 * Inf if flag_trapping_math.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3963&r2=2.3964
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/simplify-rtx.c.diff?cvsroot=gcc&r1=1.192&r2=1.193

Comment 3 GCC Commits 2004-06-14 17:48:04 UTC
Subject: Bug 15945

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	jakub@gcc.gnu.org	2004-06-14 17:48:02

Modified files:
	gcc            : ChangeLog simplify-rtx.c 

Log message:
	PR middle-end/15945
	* simplify-rtx.c (simplify_binary_operation): Don't optimize out
	Inf + -Inf, Inf - Inf, Inf / Inf and 0 * Inf if flag_trapping_math.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.502&r2=2.2326.2.503
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/simplify-rtx.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.172.4.1&r2=1.172.4.2

Comment 4 Andrew Pinski 2004-06-14 19:18:11 UTC
Fixed.
Comment 5 andreasmeier80 2004-06-14 20:25:15 UTC
Target milestone should be 3.4.1.

Andreas