public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31542]  New: Incorrect optization with nan values
@ 2007-04-11 20:55 scott at minsters dot us
  2007-04-11 20:56 ` [Bug c/31542] " scott at minsters dot us
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: scott at minsters dot us @ 2007-04-11 20:55 UTC (permalink / raw)
  To: gcc-bugs

When building 64 bit with an optimization setting of -O2, -O3, or -Os, some
binary comparisons with nan values fail to produce false.  All comparisons (==,
>, <, etc) where one (or both) of the two values is nan should produce false.

There are no warnings or other error messages during compilation.  The attached
test demonstrates the error with the final assert failing.  The max() function
should return the maximum of the two values, ignoring nans.  i.e., max(5, nan)
should be 5.  This fails with gcc3.4.6 -O2 -m64.

Strangely, switching the order of the final portion of the return to something
like:

 return (a > b ? a : (b > a ? b : (isNaN(b) ? a : b)));

causes it to work.

Also, replacing isNaN() with a call to the slower, non-inline isnan() also
makes the function work.


-- 
           Summary: Incorrect optization with nan values
           Product: gcc
           Version: 3.4.6
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: scott at minsters dot us
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31542


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

* [Bug c/31542] Incorrect optization with nan values
  2007-04-11 20:55 [Bug c/31542] New: Incorrect optization with nan values scott at minsters dot us
@ 2007-04-11 20:56 ` scott at minsters dot us
  2007-04-11 21:03 ` pinskia at gcc dot gnu dot org
  2007-04-11 21:31 ` [Bug middle-end/31542] " scott at minsters dot us
  2 siblings, 0 replies; 7+ messages in thread
From: scott at minsters dot us @ 2007-04-11 20:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from scott at minsters dot us  2007-04-11 21:56 -------
Created an attachment (id=13353)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13353&action=view)
preprocessed example


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31542


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

* [Bug c/31542] Incorrect optization with nan values
  2007-04-11 20:55 [Bug c/31542] New: Incorrect optization with nan values scott at minsters dot us
  2007-04-11 20:56 ` [Bug c/31542] " scott at minsters dot us
@ 2007-04-11 21:03 ` pinskia at gcc dot gnu dot org
  2007-04-11 21:31 ` [Bug middle-end/31542] " scott at minsters dot us
  2 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-04-11 21:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-04-11 22:03 -------
Are you sure you did not have -ffast-math on the command line?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31542


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

* [Bug middle-end/31542] Incorrect optization with nan values
  2007-04-11 20:55 [Bug c/31542] New: Incorrect optization with nan values scott at minsters dot us
  2007-04-11 20:56 ` [Bug c/31542] " scott at minsters dot us
  2007-04-11 21:03 ` pinskia at gcc dot gnu dot org
@ 2007-04-11 21:31 ` scott at minsters dot us
  2 siblings, 0 replies; 7+ messages in thread
From: scott at minsters dot us @ 2007-04-11 21:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from scott at minsters dot us  2007-04-11 22:31 -------
-ffast-math was not used.  Adding that option actually makes the test work.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31542


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

* [Bug middle-end/31542] Incorrect optization with nan values
       [not found] <bug-31542-4@http.gcc.gnu.org/bugzilla/>
  2023-06-02  0:18 ` pinskia at gcc dot gnu.org
  2023-06-06 12:06 ` scott at minsters dot us
@ 2023-06-06 17:30 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-06 17:30 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.5.0
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Just closing as fixed.

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

* [Bug middle-end/31542] Incorrect optization with nan values
       [not found] <bug-31542-4@http.gcc.gnu.org/bugzilla/>
  2023-06-02  0:18 ` pinskia at gcc dot gnu.org
@ 2023-06-06 12:06 ` scott at minsters dot us
  2023-06-06 17:30 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 7+ messages in thread
From: scott at minsters dot us @ 2023-06-06 12:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Scott Minster <scott at minsters dot us> ---
Thanks for looking at this old bug.  I had totally forgotten about it myself!

I agree that it does not seem to affect any recent version of GCC.  It was
likely fixed in GCC 4, and doesn't seem to affect any later versions.

There's no good reason to spend time fixing such an old version, so this bug
can probably be closed as it is no longer relevant.

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

* [Bug middle-end/31542] Incorrect optization with nan values
       [not found] <bug-31542-4@http.gcc.gnu.org/bugzilla/>
@ 2023-06-02  0:18 ` pinskia at gcc dot gnu.org
  2023-06-06 12:06 ` scott at minsters dot us
  2023-06-06 17:30 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-02  0:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I can't reproduce this in any recent versions of GCC. Even in GCC 4.7.3 and GCC
4.6.4 it works and we get no assert.

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

end of thread, other threads:[~2023-06-06 17:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-11 20:55 [Bug c/31542] New: Incorrect optization with nan values scott at minsters dot us
2007-04-11 20:56 ` [Bug c/31542] " scott at minsters dot us
2007-04-11 21:03 ` pinskia at gcc dot gnu dot org
2007-04-11 21:31 ` [Bug middle-end/31542] " scott at minsters dot us
     [not found] <bug-31542-4@http.gcc.gnu.org/bugzilla/>
2023-06-02  0:18 ` pinskia at gcc dot gnu.org
2023-06-06 12:06 ` scott at minsters dot us
2023-06-06 17:30 ` 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).