[Bug middle-end/84997] Optimize integer operations on floating point constants without -ffast-math
joseph at codesourcery dot com
gcc-bugzilla@gcc.gnu.org
Tue Mar 20 17:37:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84997
--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Tue, 20 Mar 2018, antoshkka at gmail dot com wrote:
> For example
>
> int test2(int lhs) {
> lhs += 2.0;
> return lhs;
> }
That would need -fno-trapping-math, because if the addition results in a
double value larger than INT_MAX, under Annex F the conversion back to int
is defined to raise FE_INVALID along with producing an unspecified value.
> int test2(int lhs) {
> lhs += 2.000000000000001;
> return lhs;
> }
That's not correct to optimize unless you generate separate code for lhs
>= -2 and lhs < -2; conversion from double to int truncates, so test2 (-3)
== 0.
More information about the Gcc-bugs
mailing list