This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/84997] Optimize integer operations on floating point constants without -ffast-math


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]