This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Optimizer bug in 2.95.1
- To: Greg Wolodkin <greg at mathworks dot com>
- Subject: Re: Optimizer bug in 2.95.1
- From: Jeffrey A Law <law at cygnus dot com>
- Date: Wed, 15 Sep 1999 22:14:41 -0600
- cc: gcc-bugs at gcc dot gnu dot org, dmg at nslocum dot cs dot bell-labs dot com
- Reply-To: law at cygnus dot com
In message <199909160256.WAA18668@mojo.dhcp>you write:
> * The following is a simplified example of the problem found when
> * compiling dtoa.c using gcc 2.95.1 on my Linux box. I'm using H.J.
> * Lu's build, though I found the same problem on a build of my own
> * using straight GNU sources. The bug doesn't occur in egcs 1.1.x.
> *
> * dtoa.c can be found at http://www.cs.bell-labs.com/netlib/fp/dtoa.c.gz
> * H.J. Lu's gcc from ftp://ftp.varesearch.com/pub/support/hjl/gcc
> *
> * I suspect the word0(x) macro is confusing the optimizer, and it doesn't
> * expect me to be doing integer manipulations on a double. When compiled
> * with -O2, the value of d2 is stored *after* the bit fiddling, so the
> * subtraction takes place before the data is valid, and the output is
> * then the unsubtracted version.
> *
> * Try running compiled with -O and it works fine. With -O2 it's wrong.
> * Here you can see that the high bit subtraction happens before the
> * floating point value is actually stored:
> *
> * .stabn 68,0,43,.LM3-foo
> * .LM3:
> * xorl %edx,%edx
> * movl %eax,-8(%ebp) <--- load up x
> * movl %edx,-4(%ebp)
> * fildll -8(%ebp)
> * .stabn 68,0,46,.LM4-foo
> * .LM4:
> * addl $-32505856,-12(%ebp) <--- subtraction fiddl
> ing
> * .stabn 68,0,43,.LM5-foo
> * .LM5:
> * fstl -16(%ebp) <--- store d2
> */
>
> #define word0(x) ((unsigned long *)&x)[1]
> #define word1(x) ((unsigned long *)&x)[0]
>
> double foo(double d)
> {
> unsigned long x = word1(d)<<20;
> double d2;
>
> /* Assign a (double) value to d2 */
> d2 = x;
>
> /* Fiddle with the bits */
> word0(d2) -= 31*0x100000;
>
> return d2;
> }
Your code violates ANSI/ISO aliasing rules.
You access the memory for "d" using two different types.
Please see the FAQ.
jeff