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>,
	Jakub Jelinek <jakub@redhat.com>,
	Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] [frange] Handle relations in LTGT_EXPR.
Date: Mon, 28 Aug 2023 08:16:31 +0200	[thread overview]
Message-ID: <20230828061701.466521-1-aldyh@redhat.com> (raw)

LTGT_EXPR hasn't been handling relations, especially with NANs as a
possibility.  This handles them while documenting how relations work
in a world with NANs.

Basically we need to special case VREL_EQ before calling
frelop_early_resolve.  Note that VREL_EQ on entry to a range-op entry
is really VREL_EQ U NAN, but to make sure about the NAN possibility,
one must look at the operands.  However, even VREL_EQ U NAN is false
for LTGT_EXPR since the latter is just NE_EXPR without a NAN.

After we handle VREL_EQ, we drop down to frelop_early_resolve
pretending to be a NE_EXPR, and everything should just map correctly.

2023-08-28  Aldy Hernandez  <aldyh@redhat.com>

	* range-op-float.cc (fold_range): Handle relations.
---
 gcc/range-op-float.cc | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 14199647744..eebc73f9918 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -2204,8 +2204,23 @@ class foperator_ltgt : public range_operator
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_trio rel = TRIO_VARYING) const final override
+		   relation_trio trio = TRIO_VARYING) const final override
   {
+    relation_kind rel = trio.op1_op2 ();
+
+    // VREL_EQ is really VREL_(UN)EQ because we could have a NAN in
+    // the operands, but since LTGT_EXPR is really a NE_EXPR without
+    // the NAN, VREL_EQ & LTGT_EXPR is an impossibility.
+    if (rel == VREL_EQ)
+      {
+	r = range_false (type);
+	return true;
+      }
+    // ...otherwise pretend we're trying to resolve a NE_EXPR and
+    // everything will "just work".
+    if (frelop_early_resolve (r, type, op1, op2, trio, VREL_NE))
+      return true;
+
     if (op1.known_isnan () || op2.known_isnan ())
       {
 	r = range_false (type);
@@ -2218,7 +2233,7 @@ public:
     if (op2.maybe_isnan ())
       op2_no_nan.clear_nan ();
     if (!range_op_handler (NE_EXPR).fold_range (r, type, op1_no_nan,
-						op2_no_nan, rel))
+						op2_no_nan, trio))
       return false;
     // The result is the same as the ordered version when the
     // comparison is true or when the operands cannot be NANs.
-- 
2.41.0


                 reply	other threads:[~2023-08-28  6:17 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=20230828061701.466521-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).