public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: GCC patches <gcc-patches@gcc.gnu.org>,
	Andrew MacLeod <amacleod@redhat.com>,
	Aldy Hernandez <aldyh@redhat.com>
Subject: [PATCH] Check rvc_normal in real_isdenormal.
Date: Fri, 14 Oct 2022 16:30:47 +0200	[thread overview]
Message-ID: <20221014143047.672008-1-aldyh@redhat.com> (raw)

[Jakub, thanks for pointing this out.  OK?]

[-Inf, -Inf] is being flushed to [-Inf, -0.0] because real_isdenormal
is being overly pessimistic.  It is missing a check for rvc_normal.
This doesn't cause problems in real.cc because all uses of
real_isdenormal are already on the rvc_normal path.  The uses in
value-range.cc however, are not.

This patch adds a check for rvc_normal.

gcc/ChangeLog:

	* real.h (real_isdenormal): Check rvc_normal.
	* value-range.cc (range_tests_floats): New test.
---
 gcc/real.h         | 2 +-
 gcc/value-range.cc | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/real.h b/gcc/real.h
index f9528d765ec..306e9593866 100644
--- a/gcc/real.h
+++ b/gcc/real.h
@@ -290,7 +290,7 @@ extern bool real_issignaling_nan (const REAL_VALUE_TYPE *);
 inline bool
 real_isdenormal (const REAL_VALUE_TYPE *r)
 {
-  return (r->sig[SIGSZ-1] & SIG_MSB) == 0;
+  return r->cl == rvc_normal && (r->sig[SIGSZ-1] & SIG_MSB) == 0;
 }
 
 /* Determine whether a floating-point value X is finite.  */
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 6b4f3dddcd5..ee15eb35df8 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -4014,6 +4014,11 @@ range_tests_floats ()
   r1.clear_nan ();
   r0.intersect (r1);
   ASSERT_TRUE (r0.undefined_p ());
+
+  // Make sure [-Inf, -Inf] doesn't get normalized.
+  r0 = frange_float ("-Inf", "-Inf");
+  ASSERT_TRUE (real_isinf (&r0.lower_bound (), true));
+  ASSERT_TRUE (real_isinf (&r0.upper_bound (), true));
 }
 
 void
-- 
2.37.3


             reply	other threads:[~2022-10-14 14:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 14:30 Aldy Hernandez [this message]
2022-10-14 14:37 ` Jakub Jelinek

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=20221014143047.672008-1-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /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).