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-3860] Clear NAN when reading back a global range if necessary.
Date: Wed,  9 Nov 2022 17:21:31 +0000 (GMT)	[thread overview]
Message-ID: <20221109172131.C2EE23858434@sourceware.org> (raw)

https://gcc.gnu.org/g:4eadbe80060ab6c45193a1a57fac84b035e1c328

commit r13-3860-g4eadbe80060ab6c45193a1a57fac84b035e1c328
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 9 16:05:08 2022 +0100

    Clear NAN when reading back a global range if necessary.
    
    When reading back from the global store, we must clear the NAN bit if
    necessary.  The reason it's not happening is because the constructor
    sets a NAN by default (when HONOR_NANS).  We must be careful to clear
    the NAN bit if the original range didn't have a NAN.
    
    I have commented the reason we use the constructor instead of filling
    out the fields by hand, because it wasn't clear at re-reading this
    code.
    
            PR 107569/tree-optimization
    
    gcc/ChangeLog:
    
            * value-range-storage.cc (frange_storage_slot::get_frange): Clear
            NAN if appropriate.
            * value-range.cc (range_tests_floats): New test.

Diff:
---
 gcc/value-range-storage.cc | 9 ++++++++-
 gcc/value-range.cc         | 9 +++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index 462447ba250..b57701f0ea1 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -276,13 +276,20 @@ frange_storage_slot::get_frange (frange &r, tree type) const
       return;
     }
 
-  // Use the constructor because it will canonicalize the range.
+  // We use the constructor to create the new range instead of writing
+  // out the bits into the frange directly, because the global range
+  // being read may be being inlined into a function with different
+  // restrictions as when it was originally written.  We want to make
+  // sure the resulting range is canonicalized correctly for the new
+  // consumer.
   r = frange (type, m_min, m_max, m_kind);
 
   // The constructor will set the NAN bits for HONOR_NANS, but we must
   // make sure to set the NAN sign if known.
   if (HONOR_NANS (type) && (m_pos_nan ^ m_neg_nan) == 1)
     r.update_nan (m_neg_nan);
+  else if (!m_pos_nan && !m_neg_nan)
+    r.clear_nan ();
 }
 
 bool
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 859c7fb4af9..852ac09f2c4 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -4051,6 +4051,15 @@ range_tests_floats ()
       ASSERT_TRUE (real_isinf (&r0.lower_bound (), true));
       ASSERT_TRUE (real_isinf (&r0.upper_bound (), true));
     }
+
+  // Test that reading back a global range yields the same result as
+  // what we wrote into it.
+  tree ssa = make_temp_ssa_name (float_type_node, NULL, "blah");
+  r0.set_varying (float_type_node);
+  r0.clear_nan ();
+  set_range_info (ssa, r0);
+  get_global_range_query ()->range_of_expr (r1, ssa);
+  ASSERT_EQ (r0, r1);
 }
 
 // Run floating range tests for various combinations of NAN and INF

                 reply	other threads:[~2022-11-09 17:21 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=20221109172131.C2EE23858434@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).