Consider the following function : // Forces a double to memory double force2memdouble(double x) { asm("" : "=m"(x) : "m"(x)); return x; } This is used to force a double value in memory for platforms like x86 where the FP registers have too much precision. It gets compiled by GCC (3.4 and 3.3.3, with -O2 -fomit-frame-pointer) to : force2memdouble: subl $12, %esp fldl 16(%esp) fstpl (%esp) fldl (%esp) addl $12, %esp ret I believe that the store/load is useless, and that the function could be compiled as simply : force2memdouble: fldl 4(%esp) ret It is interesting to note that when using "int", "float" or "long double" instead of "double", then there is no such useless store/load. So, is this something that could be improved in GCC ? Maybe the code responsible for asm() adds too many requirements on the operands for doubles ?
I still have gcc 2.95 around, so I have tested with it as well. It produces the better code that I expected : force2memdouble: #APP #NO_APP fldl 4(%esp) ret So, if the code is correct, then this problem is a regression on code quality compared to 2.95. I want to mention that this asm() is critical when implementing interval arithmetic. Also, GMP uses that kind of asm() in mpz_get_d_2exp.
Note before 3.3 and after 2.95.3, the following sequence was used to copy the FP: subl $12, %esp movl 16(%esp), %edx movl 20(%esp), %ecx movl %edx, (%esp) movl %ecx, 4(%esp) Confirmed as a regression.
Will not fix in 3.3.x. -- Gaby
Richard -- Would you please take a look at this? Thanks, -- Mark
Testing a patch.
Subject: Bug 15228 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: rth@gcc.gnu.org 2004-06-08 16:44:56 Modified files: gcc : ChangeLog function.c Log message: PR middle-end/15228 * function.c (assign_parms): Always set_mem_align with the computed FUNCTION_ARG_BOUNDARY. Don't clear stack_parm if !STRICT_ALIGNMENT. 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.481&r2=2.2326.2.482 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/function.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.483.4.13&r2=1.483.4.14
Subject: Bug 15228 CVSROOT: /cvs/gcc Module name: gcc Changes by: rth@gcc.gnu.org 2004-06-09 23:52:15 Modified files: gcc : ChangeLog function.c Log message: PR middle-end/15228 * function.c (assign_parms): Always set_mem_align with the computed FUNCTION_ARG_BOUNDARY. Don't clear stack_parm if !STRICT_ALIGNMENT. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3901&r2=2.3902 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/function.c.diff?cvsroot=gcc&r1=1.520&r2=1.521
Fixed.