[Bug c++/98829] New: Different results with -O3 and custom quiet NaN
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829 Bug ID: 98829 Summary: Different results with -O3 and custom quiet NaN Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gnu at nemanjaboric dot com Target Milestone: --- Created attachment 50047 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50047&action=edit Example of the code giving different results Hi, see the attached code which generates the different code with -O3 (compiled with various GCC version). Two workarounds are commented in the code: to use `std::isnan` and to copy the source object. I couldn't find anything undefined that I'm doing here but I might be wrong. -ffast-math _is not_ used. Just -O3 yields different result: https://www.godbolt.org/z/nxPd8W
[Bug middle-end/98829] Different results with -O3 and custom quiet NaN
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829 --- Comment #2 from Nemanja Boric --- Indeed, but there's a barrier in the code (is_empty) which doesn't let NaN values to enter the computation, so they shouldn't propagate.
[Bug middle-end/98829] Different results with -O3 and custom quiet NaN
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829 --- Comment #3 from Nemanja Boric --- Changing: static constexpr std::uint64_t kMagicNumber = 1730; static constexpr std::uint64_t kCustomNaN = 0x7ff0 | kMagicNumber; to static inline std::uint64_t kMagicNumber = 1730; static inline std::uint64_t kCustomNaN = 0x7ff0 | kMagicNumber; also avoids the issue.
[Bug middle-end/98829] Different results with -O3 and custom quiet NaN
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829 --- Comment #5 from Nemanja Boric --- Yes, it seems that if the constants are `constexpr` or `static inline const` the custom payload is gone. I guess this is aligned to https://en.cppreference.com/w/cpp/types/numeric_limits/quiet_NaN "A NaN never compares equal to itself. Copying a NaN may not preserve its bit representation."