This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/84997] Optimize integer operations on floating point constants without -ffast-math
- From: "antoshkka at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 21 Mar 2018 11:49:47 +0000
- Subject: [Bug middle-end/84997] Optimize integer operations on floating point constants without -ffast-math
- Auto-submitted: auto-generated
- References: <bug-84997-4@http.gcc.gnu.org/bugzilla/>
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.