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] Use frange::set_nan() from the generic frange::set().
Date: Wed, 14 Sep 2022 17:08:50 +0200	[thread overview]
Message-ID: <20220914150852.1244397-3-aldyh@redhat.com> (raw)
In-Reply-To: <20220914150852.1244397-1-aldyh@redhat.com>

This patch cleans up the frange::set() code by passing all things NAN
to frange::set_nan().

No functional changes.

Regstrapped on x86-64 Linux, plus I ran selftests for
-ffinite-math-only.

gcc/ChangeLog:

	* value-range.cc (frange::set): Use set_nan.
	* value-range.h (frange::set_nan): Inline code originally in
	set().
---
 gcc/value-range.cc | 27 ++++++++++++++-------------
 gcc/value-range.h  |  9 ++++++++-
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index dd827421aca..d759fcf178c 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -369,32 +369,33 @@ frange::set (tree min, tree max, value_range_kind kind)
       return;
     }
 
+  // Handle NANs.
+  if (real_isnan (TREE_REAL_CST_PTR (min)) || real_isnan (TREE_REAL_CST_PTR (max)))
+    {
+      gcc_checking_assert (real_identical (TREE_REAL_CST_PTR (min),
+					   TREE_REAL_CST_PTR (max)));
+      tree type = TREE_TYPE (min);
+      set_nan (type);
+      return;
+    }
+
   m_kind = kind;
   m_type = TREE_TYPE (min);
   m_props.set_varying ();
   m_min = *TREE_REAL_CST_PTR (min);
   m_max = *TREE_REAL_CST_PTR (max);
 
-  bool is_nan = (real_isnan (TREE_REAL_CST_PTR (min))
-		 || real_isnan (TREE_REAL_CST_PTR (max)));
-
-  // Ranges with a NAN and a non-NAN endpoint are nonsensical.
-  gcc_checking_assert (!is_nan || operand_equal_p (min, max));
-
-  // Set NAN property if we're absolutely sure.
-  if (is_nan && operand_equal_p (min, max))
-    m_props.nan_set_yes ();
-  else if (!HONOR_NANS (m_type))
-    m_props.nan_set_no ();
-
   // Set SIGNBIT property for positive and negative ranges.
   if (real_less (&m_max, &dconst0))
     m_props.signbit_set_yes ();
   else if (real_less (&dconst0, &m_min))
     m_props.signbit_set_no ();
 
+  if (!HONOR_NANS (m_type))
+    m_props.nan_set_no ();
+
   // Check for swapped ranges.
-  gcc_checking_assert (is_nan || tree_compare (LE_EXPR, min, max));
+  gcc_checking_assert (tree_compare (LE_EXPR, min, max));
 
   normalize_kind ();
   if (flag_checking)
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 6e896eb9ab5..4392de84c8b 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -1193,7 +1193,14 @@ frange::set_nan (tree type)
 {
   REAL_VALUE_TYPE r;
   gcc_assert (real_nan (&r, "", 1, TYPE_MODE (type)));
-  set (type, r, r);
+  m_kind = VR_RANGE;
+  m_type = type;
+  m_min = r;
+  m_max = r;
+  m_props.set_varying ();
+  m_props.nan_set_yes ();
+  if (flag_checking)
+    verify_range ();
 }
 
 // Return TRUE if range is known to be finite.
-- 
2.37.1


  parent reply	other threads:[~2022-09-14 15:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 15:08 [COMMITTED] Minor fixes to frange Aldy Hernandez
2022-09-14 15:08 ` [COMMITTED] Provide cleaner set_nan(), clear_nan(), and update_nan() methods Aldy Hernandez
2022-09-14 15:08 ` Aldy Hernandez [this message]
2022-09-14 15:08 ` [COMMITTED] Pass full range to build_* in range-op-float.cc Aldy Hernandez
2022-09-14 15:08 ` [COMMITTED] frange: add both zeros to ranges when there's the possiblity of equality 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=20220914150852.1244397-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).