If you compile the function void assign2(float* a, double b) { volatile float v = -b; *a = -v; }
you will see that GCC 3.4.3, e.g., at -O2, produces fldl 12(%ebp) fstps -20(%ebp) movl 8(%ebp), %eax flds -20(%ebp) fchs fstps -4(%ebp) flds -4(%ebp) fchs fstps (%eax) where the first sign change is performed /after/ reducing the precision and not /before/, as I believe it should (according to ISO/IEC 9899, 5.1.2.3#13, 6.3.1.5#2 and 6.3.1.8#2). The produced code seems also very badly optimized, considering that something like fldl 12(%ebp) fchs fstps -4(%ebp) flds -4(%ebp) fchs fstps (%eax) would be significantly more efficient (besides being correct). The same problem can be seen with gcc-4.0.0 20050406 (Fedora Core 3). Roberto Bagnara -- Summary: GCC 3.4.3 wrongly reorders floating-point operations Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c 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=21032