This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
optimization/9641: const double arguments and -ffloat-store do not work together
- From: richard at wetafx dot co dot nz
- To: gcc-gnats at gcc dot gnu dot org
- Date: 10 Feb 2003 07:53:20 -0000
- Subject: optimization/9641: const double arguments and -ffloat-store do not work together
- Reply-to: richard at wetafx dot co dot nz
>Number: 9641
>Category: optimization
>Synopsis: const double arguments and -ffloat-store do not work together
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon Feb 10 07:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: richard@wetafx.co.nz
>Release: gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2)
>Organization:
>Environment:
Linux 2.4.18-xfssmp #1 SMP i686
>Description:
//////////main.c
double rightfunc(double);
double wrongfunc(double);
int
main(void)
{
rightfunc(0.75);
wrongfunc(0.25);
}
//////////funcs.c
double rightfunc(double t) { return t; }
double wrongfunc(const double t) { return t; }
//////////GNUmakefile
all: wrong right
right: main.c funcs.c; gcc -O3 -o $@ main.c funcs.c
wrong: main.c funcs.c; gcc -O3 -ffloat-store -o $@ main.c funcs.c
>How-To-Repeat:
With the three supplied files, use gmake to build.
The generated 'right' file works properly, but the
generated 'wrong' file generates incorrect code for
the 'wrongfunc' function:
0x8048474 <wrongfunc>: push %ebp
0x8048475 <wrongfunc+1>: mov %esp,%ebp
0x8048477 <wrongfunc+3>: sub $0x8,%esp
0x804847a <wrongfunc+6>: fldl 0xfffffff8(%ebp)
0x804847d <wrongfunc+9>: leave
0x804847e <wrongfunc+10>: ret
0x804847f <wrongfunc+11>: nop
Basically, the code uses memory that has not be set
to the value passed as a 'const double' argument.
Note that rightfunc() has a double argument, while
wrongfunc() has a const double argument. Otherwise
they are the same.
The 'wrong' file is built with -ffloat-store while
the 'right' file is built without.
>Fix:
I can avoid 'const double' arguments, but this may
mean some sifting through large code bases.
I can avoid using -ffloat-store, but then I run into
other code generation issues because of the broken
nature how the optimizer handles comparisons with
floats and doubles on Intel.
>Release-Note:
>Audit-Trail:
>Unformatted: