Bug in builtin_floor optimization
Dale Johannesen
dalej@apple.com
Tue Aug 23 00:38:00 GMT 2005
There is some clever code in convert_to_real that converts
double d;
(float)floor(d)
to
floorf((float)d)
(on targets where floor and floorf are considered builtins.)
This is wrong, because the (float)d conversion normally uses
round-to-nearest and can round up to the next integer. For example:
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 4221664b.c
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20050823/b26dd153/attachment.c>
-------------- next part --------------
with -O2.
The transformation is also done for ceil, round, rint, trunc and
nearbyint.
I'm not a math guru, but it looks like ceil, rint, trunc and nearbyint
are
also unsafe for this transformation. round may be salvageable.
Comments? Should I preserve the buggy behavior with -ffast-math?
More information about the Gcc
mailing list