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-2741] frange::set_nonnegative should not contain -NAN. Date: Tue, 20 Sep 2022 17:36:38 +0000 (GMT) [thread overview] Message-ID: <20220920173638.84B9C3858C55@sourceware.org> (raw) https://gcc.gnu.org/g:10d6109fe183d984a0377a7afe2854a0d794ebeb commit r13-2741-g10d6109fe183d984a0377a7afe2854a0d794ebeb Author: Aldy Hernandez <aldyh@redhat.com> Date: Mon Sep 19 09:59:01 2022 +0200 frange::set_nonnegative should not contain -NAN. A specifically nonnegative range should not contain -NAN, otherwise signbit_p() would return false, because we'd be unsure of the sign. PR 68097/tree-optimization gcc/ChangeLog: * value-range.cc (frange::set_nonnegative): Set +NAN. (range_tests_signed_zeros): New test. * value-range.h (frange::update_nan): New overload to set NAN sign. Diff: --- gcc/value-range.cc | 9 +++++++++ gcc/value-range.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index a8e3bb39bab..dc42b6d3120 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -775,6 +775,10 @@ void frange::set_nonnegative (tree type) { set (type, dconst0, dconstinf); + + // Set +NAN as the only possibility. + if (HONOR_NANS (type)) + update_nan (/*sign=*/0); } // Here we copy between any two irange's. The ranges can be legacy or @@ -3823,6 +3827,11 @@ range_tests_signed_zeros () r1.update_nan (); r0.intersect (r1); ASSERT_TRUE (r0.known_isnan ()); + + r0.set_nonnegative (float_type_node); + ASSERT_TRUE (r0.signbit_p (signbit) && !signbit); + if (HONOR_NANS (float_type_node)) + ASSERT_TRUE (r0.maybe_isnan ()); } static void diff --git a/gcc/value-range.h b/gcc/value-range.h index 795b1f00fdc..7d5584a9294 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -312,6 +312,7 @@ public: const REAL_VALUE_TYPE &lower_bound () const; const REAL_VALUE_TYPE &upper_bound () const; void update_nan (); + void update_nan (bool sign); void clear_nan (); // fpclassify like API @@ -1099,6 +1100,19 @@ frange::update_nan () verify_range (); } +// Like above, but set the sign of the NAN. + +inline void +frange::update_nan (bool sign) +{ + gcc_checking_assert (!undefined_p ()); + m_pos_nan = !sign; + m_neg_nan = sign; + normalize_kind (); + if (flag_checking) + verify_range (); +} + // Clear the NAN bit and adjust the range. inline void
reply other threads:[~2022-09-20 17:36 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=20220920173638.84B9C3858C55@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: linkBe 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).