With -O1 -frounding-math on x86, the following function
double f(double a, double b, double c)
{ return a * -b + c; }
is compiled as
fldl 16(%ebp)
fmull 8(%ebp)
fsubrl 24(%ebp)
So the body of the function has been rewritten as "c - a * b". This
transformation is not correct with directed rounding (as potentially implied by
-frounding-math). When the addition is not present, GCC generates the safe
code, even with -fno-rounding-math. So it's the addition that triggers this
wrong code.
Tested with 4.1.2, 4.2.0 (from March), 4.3.0 (from January).
--
Summary: Incorrect folding of multiplication and sign change when
followed by an addition
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: guillaume dot melquiond at ens-lyon dot fr
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31530