public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] Disallow setting of NANs in frange setter unless setting trees.
Date: Thu, 25 May 2023 07:35:19 +0200	[thread overview]
Message-ID: <20230525053520.244673-3-aldyh@redhat.com> (raw)
In-Reply-To: <20230525053520.244673-1-aldyh@redhat.com>

frange::set() is confusing in that we can set a NAN by specifying a
bound of +-NAN, even though we tecnically disallow NANs in the setter
because the kind can never be VR_NAN.  This is a wart for
get_tree_range(), which builds a range out of a tree from the source,
to work correctly.  It's ugly, and it showed its limitation while
implementing LTO streaming of ranges.

This patch disallows passing NAN bounds in frange::set() and fixes
get_tree_range.

gcc/ChangeLog:

	* value-query.cc (range_query::get_tree_range): Set NAN directly
	if necessary.
	* value-range.cc (frange::set): Assert that bounds are not NAN.
---
 gcc/value-query.cc | 13 ++++++++++---
 gcc/value-range.cc |  9 +--------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/value-query.cc b/gcc/value-query.cc
index 43297f17c39..a84f164d77b 100644
--- a/gcc/value-query.cc
+++ b/gcc/value-query.cc
@@ -189,9 +189,16 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt)
       {
 	frange &f = as_a <frange> (r);
 	REAL_VALUE_TYPE *rv = TREE_REAL_CST_PTR (expr);
-	f.set (TREE_TYPE (expr), *rv, *rv);
-	if (!real_isnan (rv))
-	  f.clear_nan ();
+	if (real_isnan (rv))
+	  {
+	    bool sign = real_isneg (rv);
+	    f.set_nan (TREE_TYPE (expr), sign);
+	  }
+	else
+	  {
+	    nan_state nan (false);
+	    f.set (TREE_TYPE (expr), *rv, *rv, nan);
+	  }
 	return true;
       }
 
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 2f37ff3e58e..707b1f15fd4 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -359,14 +359,7 @@ frange::set (tree type,
       gcc_unreachable ();
     }
 
-  // Handle NANs.
-  if (real_isnan (&min) || real_isnan (&max))
-    {
-      gcc_checking_assert (real_identical (&min, &max));
-      bool sign = real_isneg (&min);
-      set_nan (type, sign);
-      return;
-    }
+  gcc_checking_assert (!real_isnan (&min) && !real_isnan (&max));
 
   m_kind = kind;
   m_type = type;
-- 
2.40.1


  parent reply	other threads:[~2023-05-25  5:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25  5:35 [COMMITTED] Add an frange::set_nan() variant that takes a nan_state Aldy Hernandez
2023-05-25  5:35 ` [COMMITTED] Hash known NANs correctly for franges Aldy Hernandez
2023-05-25  5:35 ` Aldy Hernandez [this message]
2023-05-25  5:35 ` [COMMITTED] Stream out NANs correctly Aldy Hernandez

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=20230525053520.244673-3-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@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).