* [Bug middle-end/98829] Different results with -O3 and custom quiet NaN
2021-01-25 22:32 [Bug c++/98829] New: Different results with -O3 and custom quiet NaN gnu at nemanjaboric dot com
@ 2021-01-25 22:55 ` pinskia at gcc dot gnu.org
2021-01-25 22:59 ` gnu at nemanjaboric dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-01-25 22:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
NaNs do prograte but as far as I know can change values as long as it is still
a NaN.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/98829] Different results with -O3 and custom quiet NaN
2021-01-25 22:32 [Bug c++/98829] New: Different results with -O3 and custom quiet NaN gnu at nemanjaboric dot com
2021-01-25 22:55 ` [Bug middle-end/98829] " pinskia at gcc dot gnu.org
@ 2021-01-25 22:59 ` gnu at nemanjaboric dot com
2021-01-25 23:18 ` gnu at nemanjaboric dot com
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: gnu at nemanjaboric dot com @ 2021-01-25 22:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829
--- Comment #2 from Nemanja Boric <gnu at nemanjaboric dot com> ---
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/98829] Different results with -O3 and custom quiet NaN
2021-01-25 22:32 [Bug c++/98829] New: Different results with -O3 and custom quiet NaN gnu at nemanjaboric dot com
2021-01-25 22:55 ` [Bug middle-end/98829] " pinskia at gcc dot gnu.org
2021-01-25 22:59 ` gnu at nemanjaboric dot com
@ 2021-01-25 23:18 ` gnu at nemanjaboric dot com
2021-01-26 8:20 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: gnu at nemanjaboric dot com @ 2021-01-25 23:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829
--- Comment #3 from Nemanja Boric <gnu at nemanjaboric dot com> ---
Changing:
static constexpr std::uint64_t kMagicNumber = 1730;
static constexpr std::uint64_t kCustomNaN = 0x7ff0000000000000 |
kMagicNumber;
to
static inline std::uint64_t kMagicNumber = 1730;
static inline std::uint64_t kCustomNaN = 0x7ff0000000000000 | kMagicNumber;
also avoids the issue.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/98829] Different results with -O3 and custom quiet NaN
2021-01-25 22:32 [Bug c++/98829] New: Different results with -O3 and custom quiet NaN gnu at nemanjaboric dot com
` (2 preceding siblings ...)
2021-01-25 23:18 ` gnu at nemanjaboric dot com
@ 2021-01-26 8:20 ` rguenth at gcc dot gnu.org
2021-01-26 11:02 ` gnu at nemanjaboric dot com
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-26 8:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is likely GCC canonicalizing the NaN somewhere and your is_value
doing a 1:1 bit comparison. In particular we optimize MyNAN::value to
MyNAN::value ()
{
<bb 2> [local count: 1073741824]:
return Nan;
but ::is_value is
MyNAN::is_value (double d)
{
long unsigned int _2;
bool _3;
<bb 2> [local count: 1073741824]:
_2 = VIEW_CONVERT_EXPR<long unsigned int>(d_1(D));
_3 = _2 == 9218868437227407042;
return _3;
MyNAN::value is optimized by CSE via native_encode/interpret.
I'm not sure why -O2 vs. -O3 makes a difference in the end but I think
your program is ill-formed.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/98829] Different results with -O3 and custom quiet NaN
2021-01-25 22:32 [Bug c++/98829] New: Different results with -O3 and custom quiet NaN gnu at nemanjaboric dot com
` (3 preceding siblings ...)
2021-01-26 8:20 ` rguenth at gcc dot gnu.org
@ 2021-01-26 11:02 ` gnu at nemanjaboric dot com
2021-01-27 16:42 ` jakub at gcc dot gnu.org
2022-01-26 14:59 ` nemanjab at amazon dot com
6 siblings, 0 replies; 8+ messages in thread
From: gnu at nemanjaboric dot com @ 2021-01-26 11:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829
--- Comment #5 from Nemanja Boric <gnu at nemanjaboric dot com> ---
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."
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/98829] Different results with -O3 and custom quiet NaN
2021-01-25 22:32 [Bug c++/98829] New: Different results with -O3 and custom quiet NaN gnu at nemanjaboric dot com
` (4 preceding siblings ...)
2021-01-26 11:02 ` gnu at nemanjaboric dot com
@ 2021-01-27 16:42 ` jakub at gcc dot gnu.org
2022-01-26 14:59 ` nemanjab at amazon dot com
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-27 16:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Your custom quiet NaN is not a quiet NaN, but signaling NaN.
And, as documented, -fno-signaling-nans is the default.
If you change your custom signaling NaN into a quiet NaN,
static constexpr std::uint64_t kCustomNaN = 0x7ff8000000000000 | kMagicNumber;
or if you compile with -fsignaling-nans, this works fine, so I'd say this is
just a user error.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/98829] Different results with -O3 and custom quiet NaN
2021-01-25 22:32 [Bug c++/98829] New: Different results with -O3 and custom quiet NaN gnu at nemanjaboric dot com
` (5 preceding siblings ...)
2021-01-27 16:42 ` jakub at gcc dot gnu.org
@ 2022-01-26 14:59 ` nemanjab at amazon dot com
6 siblings, 0 replies; 8+ messages in thread
From: nemanjab at amazon dot com @ 2022-01-26 14:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829
Nemanja Boric <nemanjab at amazon dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nemanjab at amazon dot com
--- Comment #7 from Nemanja Boric <nemanjab at amazon dot com> ---
Sorry for the late reply. Yes, you're right, this is an user error.
^ permalink raw reply [flat|nested] 8+ messages in thread