public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102549] New: Incorrect optimization if argument is SNAN
@ 2021-09-30 18:38 Serge.Pavlov.at.gnu at gmail dot com
2021-09-30 19:19 ` [Bug c/102549] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Serge.Pavlov.at.gnu at gmail dot com @ 2021-09-30 18:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102549
Bug ID: 102549
Summary: Incorrect optimization if argument is SNAN
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: Serge.Pavlov.at.gnu at gmail dot com
Target Milestone: ---
GCC was taken at https://godbolt.org, the reported version is:
gcc
(Compiler-Explorer-Build-gcc-d6a87d96d7473cbd2404d5dcc7eef36a7f53b2b2-binutils-2.36.1)
12.0.0 20210929 (experimental)
The program is:
extern int printf(const char *fmt, ...);
union {
double f;
long long i;
} val;
double add_zero(double x) {
return x + -0.0;
}
int main(int arc, char *argv[]) {
val.i = 0x7ff4000000000000LL; // SNaN
val.f = add_zero(val.f);
printf("%llx\n", val.i);
return 0;
}
Compiled with options "-O2" this program prints
(https://godbolt.org/z/YE13qEhf9):
7ff4000000000000
This is incorrect as this is SNaN, but according to IEEE 754-2008, 6.2:
Under default exception handling, any operation signaling an invalid operation
exception and for which a
floating-point result is to be delivered shall deliver a quiet NaN.
Signaling NaNs shall be reserved operands that, under default exception
handling, signal the invalid
operation exception (see 7.2) for every general-computational and
signaling-computational operation except
for the conversions described in 5.12.
And according to the latest standard draft
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2596.pdf), F.3p1:
C operators, functions, and function-like macros provide operations specified
by IEC 60559 as shown
in the following table. ... The C specifications are
intended to match IEC 60559, unless stated otherwise.
So a QNaN is expected here.
If "-0.0" is replaced with the positive zero:
double add_zero(double x) {
return x + 0.0;
}
the behavior is as expected, the program prints:
7ffc000000000000
which is QNaN.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/102549] Incorrect optimization if argument is SNAN
2021-09-30 18:38 [Bug c/102549] New: Incorrect optimization if argument is SNAN Serge.Pavlov.at.gnu at gmail dot com
@ 2021-09-30 19:19 ` pinskia at gcc dot gnu.org
2021-09-30 19:20 ` pinskia at gcc dot gnu.org
2021-09-30 20:43 ` [Bug middle-end/102549] " pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-30 19:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102549
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think you need -fsignaling-nans
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/102549] Incorrect optimization if argument is SNAN
2021-09-30 18:38 [Bug c/102549] New: Incorrect optimization if argument is SNAN Serge.Pavlov.at.gnu at gmail dot com
2021-09-30 19:19 ` [Bug c/102549] " pinskia at gcc dot gnu.org
@ 2021-09-30 19:20 ` pinskia at gcc dot gnu.org
2021-09-30 20:43 ` [Bug middle-end/102549] " pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-30 19:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102549
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note also from the docs:
This option is experimental and does not currently guarantee to disable all GCC
optimizations that affect signaling NaN behavior.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/102549] Incorrect optimization if argument is SNAN
2021-09-30 18:38 [Bug c/102549] New: Incorrect optimization if argument is SNAN Serge.Pavlov.at.gnu at gmail dot com
2021-09-30 19:19 ` [Bug c/102549] " pinskia at gcc dot gnu.org
2021-09-30 19:20 ` pinskia at gcc dot gnu.org
@ 2021-09-30 20:43 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-30 20:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102549
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes you need to use -fsignaling-nans.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-30 20:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30 18:38 [Bug c/102549] New: Incorrect optimization if argument is SNAN Serge.Pavlov.at.gnu at gmail dot com
2021-09-30 19:19 ` [Bug c/102549] " pinskia at gcc dot gnu.org
2021-09-30 19:20 ` pinskia at gcc dot gnu.org
2021-09-30 20:43 ` [Bug middle-end/102549] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).