optimization/9641: const double arguments and -ffloat-store do not work together

richard@wetafx.co.nz richard@wetafx.co.nz
Mon Feb 10 07:56:00 GMT 2003

>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
>Originator:     richard@wetafx.co.nz
>Release:        gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2)
Linux 2.4.18-xfssmp #1 SMP i686
double rightfunc(double);
double wrongfunc(double);
double rightfunc(double t) { return t; }
double wrongfunc(const double t) { return t; }
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
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.
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.

More information about the Gcc-bugs mailing list