public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95351] New: Comparison with NAN optimizes incorrectly with -ffast-math disabled
@ 2020-05-26 21:39 chris.dahlberg at cytovale dot com
  2020-05-26 22:22 ` [Bug c++/95351] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: chris.dahlberg at cytovale dot com @ 2020-05-26 21:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95351

            Bug ID: 95351
           Summary: Comparison with NAN optimizes incorrectly with
                    -ffast-math disabled
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chris.dahlberg at cytovale dot com
  Target Milestone: ---

Created attachment 48610
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48610&action=edit
nan_bug.ii:  preprocessed output from --save-temps

The function

bool Foo(double possiblyNAN, double b, double c)
{
    return (possiblyNAN <= 2.0) || ((possiblyNAN  > 2.0) && (b > c));
}


is optimized incorrectly with -O1.  It gets reduced to just '(b > c)', ignoring
the possibility that 'possiblyNAN' is NAN and both comparisons vs 2.0 are
false.  -ffinite-math-only is off (both by default and explicitly, no
difference)

The command line I'm using is:

"g++ -Wall -Wextra -O -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -fno-finite-math-only nan_bug.cpp"

No warnings are output

Looking at the assembly, 'possiblyNAN' is never accessed at all

Tried this on these gcc versions and all have the same behavior:
- gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
- gcc version 8.4.0 (Ubuntu 8.4.0-1ubuntu1~18.04)
- gcc version 10.1.0 (Compiler-Explorer-Build)
- gcc version 11.0.0 20200525 (experimental) (Compiler-Explorer-Build)

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-05-08 16:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 21:39 [Bug c++/95351] New: Comparison with NAN optimizes incorrectly with -ffast-math disabled chris.dahlberg at cytovale dot com
2020-05-26 22:22 ` [Bug c++/95351] " pinskia at gcc dot gnu.org
2020-05-26 23:07 ` glisse at gcc dot gnu.org
2024-03-10  3:44 ` [Bug middle-end/95351] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-03-10 21:06 ` pinskia at gcc dot gnu.org
2024-03-11  2:59 ` cvs-commit at gcc dot gnu.org
2024-03-11  2:59 ` [Bug middle-end/95351] [11/12/13 " pinskia at gcc dot gnu.org
2024-03-12  6:41 ` cvs-commit at gcc dot gnu.org
2024-03-12  6:42 ` [Bug middle-end/95351] [11/12 " pinskia at gcc dot gnu.org
2024-05-08 16:16 ` cvs-commit at gcc dot gnu.org
2024-05-08 16:19 ` cvs-commit at gcc dot gnu.org
2024-05-08 16:19 ` 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).