This is the mail archive of the
mailing list for the GCC project.
optimization/9840: Incorrect optimization for floating-point aliasing to int
- From: gsasha at cs dot technion dot ac dot il
- To: gcc-gnats at gcc dot gnu dot org
- Date: 24 Feb 2003 21:16:06 -0000
- Subject: optimization/9840: Incorrect optimization for floating-point aliasing to int
- Reply-to: gsasha at cs dot technion dot ac dot il
>Synopsis: Incorrect optimization for floating-point aliasing to int
>Arrival-Date: Mon Feb 24 21:26:00 UTC 2003
>Originator: Alex Gontmakher
>Release: gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-2mdk)
machine: Athlon MP 1800
The following code worked with previous versions of GCC, producing either 1 or 0. Now it produces 2.
A workaround is to uncomment the printf() line - obviously causes it to perform the initialization of the float prior to executing the ifs.
The problem happens only at optimization level O2 or higher.
double x = 1.0;
/* NOTE: this check assumes IEEE floating point format */
p = (int *)&x;
if (*p == 0)
else if (*p == 0x3ff00000)
std::cout << f() << std::endl;
I didn't read the optimization code for this, but it should probably notice that p aliases &x, and perform the initialization of x prior to reading *p.