[Bug middle-end/84997] Optimize integer operations on floating point constants without -ffast-math
antoshkka at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Mar 21 11:49:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84997
--- Comment #3 from Antony Polukhin <antoshkka at gmail dot com> ---
(In reply to Richard Biener from comment #2)
<...>
> If it produces an unspecified value it doesn't raise undefined behavior,
> right?
> So replacing it with lhs += 2; is incorrect as if that overflows that's
> undefined behavior. So we could only replace it with lhs =
> (int)((unsigned)lhs + 2) and produce implementation defined behavior from
> "unspecified" which I suppose is OK.
There's a subset of cases that do not touch UBs and are possible to implement
without fp:
unsigned long long test01(unsigned lhs) {
return lhs + 2.0; // Never overflows
}
unsigned test02(unsigned lhs) {
return lhs + 2.0; // No signed overflow
}
Both of the above cases clang optimizes into integral addition.
More information about the Gcc-bugs
mailing list