Compiling the following with GCC 3.4.3 (with "gcc -O2 -S file.c")
float mul2(float a, float b) { float v = -a * b; return -v; } produce the erroneous code pushl %ebp movl %esp, %ebp flds 8(%ebp) fmuls 12(%ebp) popl %ebp ret where the sign changes have been erroneously elided. Notice that, depending on the rounding mode in effect, this produces the wrong results. Strangely enough, the code produced for float div2(float a, float b) { float v = -a / b; return -v; } is instead correct. -- Summary: Excessive optimization of floating point expression Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bagnara at cs dot unipr dot it CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21067