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] frange::set_signbit: Avoid changing sign when already in the correct sign.
Date: Mon, 12 Sep 2022 15:07:12 +0200	[thread overview]
Message-ID: <20220912130711.484083-1-aldyh@redhat.com> (raw)

We should avoid pessimizing the signbit when it's already correct.  In
this particular case we were trying to change the signbit to "unknown",
when it was obviously negative.

This test is actually slated for removal with my upcoming revamp of the
signbit and NAN tracking, per the conversations regarding tristate.  The
signbit will be removed in favor of keeping track of it in the range
itself, and NAN will just be a pair of boolean flags.  However, I don't
plan to disturb the tree until after Cauldron.

Tested on x86-64 Linux including mpfr tests.  Also tested selftests with
-ffinite-math-only on x86-64 as well as on a cross to pdp11-aout.

gcc/ChangeLog:

	* value-range.cc (frange::set_signbit): Avoid changing sign when
	already in the correct sign.
---
 gcc/value-range.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index adcaaa2a69a..6f0609959b3 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -316,9 +316,13 @@ frange::set_signbit (fp_prop::kind k)
   // Ignore sign changes when they're set correctly.
   if (!maybe_nan ())
     {
-      if (real_less (&m_max, &dconst0))
+      // It's negative and we're trying to make it negative or varying.
+      if (real_less (&m_max, &dconst0) && (k == fp_prop::YES
+					   || k == fp_prop::VARYING))
 	return;
-      if (real_less (&dconst0, &m_min))
+      // It's positive and we're trying to make it positive or varying.
+      if (real_less (&dconst0, &m_min) && (k == fp_prop::NO
+					   || k == fp_prop::VARYING))
 	return;
     }
   // Adjust the range depending on the sign bit.
-- 
2.37.1


                 reply	other threads:[~2022-09-12 13:07 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=20220912130711.484083-1-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).