public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110305] New: Incorrect optimization with -O3 -fsignaling-nans -fno-signed-zeros
@ 2023-06-19  6:08 tkisuki at tachyum dot com
  2023-06-19  6:15 ` [Bug c/110305] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: tkisuki at tachyum dot com @ 2023-06-19  6:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110305
           Summary: Incorrect optimization with -O3 -fsignaling-nans
                    -fno-signed-zeros
           Product: gcc
           Version: og12 (devel/omp/gcc-12)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tkisuki at tachyum dot com
  Target Milestone: ---

float f(float a)
{
  return a + 0.0f;
}

Compiling the above code with -O3 -fsignaling-nans -fno-signed-zeros simplifies
'a + 0' to 'a'.

It seems '-fsignaling-nans' is not considered for this simplification.

Simplification is done by simplify_context::simplify_binary_operation_1()
function in gcc/simplify-rtx.cc.

'-fsignaling-nans' is experimental, but can the condition also check
!HONOR_SNANS(mode)? 

--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -2698,7 +2698,8 @@ simplify_context::simplify_binary_operation_1 (rtx_code
code,
         when x is NaN, infinite, or finite and nonzero.  They aren't
         when x is -0 and the rounding mode is not towards -infinity,
         since (-0) + 0 is then 0.  */
-      if (!HONOR_SIGNED_ZEROS (mode) && trueop1 == CONST0_RTX (mode))
+      if (!HONOR_SIGNED_ZEROS (mode) && !HONOR_SNANS (mode)
+          && trueop1 == CONST0_RTX (mode))
        return op0;

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

end of thread, other threads:[~2023-06-20 21:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-19  6:08 [Bug c/110305] New: Incorrect optimization with -O3 -fsignaling-nans -fno-signed-zeros tkisuki at tachyum dot com
2023-06-19  6:15 ` [Bug c/110305] " pinskia at gcc dot gnu.org
2023-06-19  6:50 ` tkisuki at tachyum dot com
2023-06-19  8:04 ` [Bug rtl-optimization/110305] " rguenth at gcc dot gnu.org
2023-06-19 10:34 ` tkisuki at tachyum dot com
2023-06-19 17:53 ` cvs-commit at gcc dot gnu.org
2023-06-19 18:52 ` mmorrell at tachyum dot com
2023-06-19 20:07 ` pinskia at gcc dot gnu.org
2023-06-19 20:41 ` mmorrell at tachyum dot com
2023-06-20 21:46 ` mmorrell at tachyum dot com

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).