public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-2225] [ranger] x == -0.0 does not mean we can replace x with -0.0
Date: Fri, 26 Aug 2022 16:14:07 +0000 (GMT)	[thread overview]
Message-ID: <20220826161407.2D24838515ED@sourceware.org> (raw)

https://gcc.gnu.org/g:d085901e0e3b3d490fb756b3e939750e7ea2b7fc

commit r13-2225-gd085901e0e3b3d490fb756b3e939750e7ea2b7fc
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Fri Aug 26 16:55:52 2022 +0200

    [ranger] x == -0.0 does not mean we can replace x with -0.0
    
    On the true side of x == -0.0, we can't just blindly value propagate
    the -0.0 into every use of x because x could be +0.0.
    
    With this change, we only allow the transformation if
    !HONOR_SIGNED_ZEROS or if the range is known not to contain 0.
    
    gcc/ChangeLog:
    
            * range-op-float.cc (foperator_equal::op1_range): Do not blindly
            copy op2 range when honoring signed zeros.

Diff:
---
 gcc/range-op-float.cc | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index ad2fae578d2..ff9fe312acf 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -252,8 +252,21 @@ foperator_equal::op1_range (frange &r, tree type,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      // If it's true, the result is the same as OP2.
-      r = op2;
+      if (HONOR_SIGNED_ZEROS (type)
+	  && op2.contains_p (build_zero_cst (type)))
+	{
+	  // With signed zeros, x == -0.0 does not mean we can replace
+	  // x with -0.0, because x may be either +0.0 or -0.0.
+	  r.set_varying (type);
+	}
+      else
+	{
+	  // If it's true, the result is the same as OP2.
+	  //
+	  // If the range does not actually contain zeros, this should
+	  // always be OK.
+	  r = op2;
+	}
       // The TRUE side of op1 == op2 implies op1 is !NAN.
       r.set_nan (fp_prop::NO);
       break;

                 reply	other threads:[~2022-08-26 16:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220826161407.2D24838515ED@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).