public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Andrew MacLeod <amacleod@redhat.com>
Cc: Aldy Hernandez <aldyh@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [RFC PATCH] range-op-float: Fix up op1_op2_relation of comparisons
Date: Wed, 12 Apr 2023 12:33:39 +0200	[thread overview]
Message-ID: <ZDaJA+nwtb3wr2SR@tucnak> (raw)
In-Reply-To: <7ad17002-8df2-c268-03f5-902ed57f3a97@redhat.com>

On Tue, Apr 11, 2023 at 04:58:19PM -0400, Andrew MacLeod wrote:
> This bootstraps and has no regressions, and is fine by me if you want to use
> it.

Thanks, looks nice.
My incremental patch on top of that would then be below.

Though,
FAIL: gcc.dg/tree-ssa/vrp-float-6.c scan-tree-dump-times evrp "Folding predicate x_.* <= y_.* to 1" 1
still FAILs with those 2 patches together.
Shall we just xfail it for now and find some solution for GCC 14?

2023-04-12  Jakub Jelinek  <jakub@redhat.com>

	* range-op-float.cc (foperator_lt::op1_op2_relation): Return
	VREL_VARYING instead of VREL_GE if HONOR_NANS and op1 or op2 could be
	NANs.
	(foperator_le::op1_op2_relation): Similarly return VREL_VARYING
	instead of VREL_GT.
	(foperator_gt::op1_op2_relation): Similarly return VREL_VARYING
	instead of VREL_LE.
	(foperator_ge::op1_op2_relation): Similarly return VREL_VARYING
	instead of VREL_LT.
	(foperator_unordered_lt::op1_op2_relation,
	foperator_unordered_le::op1_op2_relation,
	foperator_unordered_gt::op1_op2_relation,
	foperator_unordered_ge::op1_op2_relation): New.

--- gcc/range-op-float.cc.jj	2023-04-12 12:17:44.784962757 +0200
+++ gcc/range-op-float.cc	2023-04-12 12:26:11.740657502 +0200
@@ -835,10 +835,18 @@ public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
 		   relation_trio = TRIO_VARYING) const final override;
-  relation_kind op1_op2_relation (const irange &lhs, const frange &,
-				  const frange &) const final override
+  relation_kind op1_op2_relation (const irange &lhs, const frange &op1,
+				  const frange &op2) const final override
   {
-    return lt_op1_op2_relation (lhs);
+    relation_kind ret = lt_op1_op2_relation (lhs);
+    if (ret == VREL_GE
+	&& HONOR_NANS (op1.type ())
+	&& (op1.known_isnan ()
+	    || op1.maybe_isnan ()
+	    || op2.known_isnan ()
+	    || op2.maybe_isnan ()))
+      ret = VREL_VARYING; // Inverse of VREL_LT is VREL_UNGE with NAN ops.
+    return ret;
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
@@ -952,9 +960,18 @@ public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
 		   relation_trio rel = TRIO_VARYING) const final override;
-  relation_kind op1_op2_relation (const irange &lhs, const frange &,
-				  const frange &) const final override
+  relation_kind op1_op2_relation (const irange &lhs, const frange &op1,
+				  const frange &op2) const final override
   {
+    relation_kind ret = le_op1_op2_relation (lhs);
+    if (ret == VREL_GT
+	&& HONOR_NANS (op1.type ())
+	&& (op1.known_isnan ()
+	    || op1.maybe_isnan ()
+	    || op2.known_isnan ()
+	    || op2.maybe_isnan ()))
+      ret = VREL_VARYING; // Inverse of VREL_LE is VREL_UNGT with NAN ops.
+    return ret;
     return le_op1_op2_relation (lhs);
   }
   bool op1_range (frange &r, tree type,
@@ -1063,10 +1080,18 @@ public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
 		   relation_trio = TRIO_VARYING) const final override;
-  relation_kind op1_op2_relation (const irange &lhs, const frange &,
-				  const frange &) const final override
+  relation_kind op1_op2_relation (const irange &lhs, const frange &op1,
+				  const frange &op2) const final override
   {
-    return gt_op1_op2_relation (lhs);
+    relation_kind ret = gt_op1_op2_relation (lhs);
+    if (ret == VREL_LE
+	&& HONOR_NANS (op1.type ())
+	&& (op1.known_isnan ()
+	    || op1.maybe_isnan ()
+	    || op2.known_isnan ()
+	    || op2.maybe_isnan ()))
+      ret = VREL_VARYING; // Inverse of VREL_GT is VREL_UNLE with NAN ops.
+    return ret;
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
@@ -1184,10 +1209,18 @@ public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
 		   relation_trio = TRIO_VARYING) const final override;
-  relation_kind op1_op2_relation (const irange &lhs, const frange &,
-				  const frange &) const final override
+  relation_kind op1_op2_relation (const irange &lhs, const frange &op1,
+				  const frange &op2) const final override
   {
-    return ge_op1_op2_relation (lhs);
+    relation_kind ret = ge_op1_op2_relation (lhs);
+    if (ret == VREL_LT
+	&& HONOR_NANS (op1.type ())
+	&& (op1.known_isnan ()
+	    || op1.maybe_isnan ()
+	    || op2.known_isnan ()
+	    || op2.maybe_isnan ()))
+      ret = VREL_VARYING; // Inverse of VREL_GE is VREL_UNLT with NAN ops.
+    return ret;
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
@@ -1581,6 +1614,7 @@ class foperator_unordered_lt : public ra
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
+  using range_operator_float::op1_op2_relation;
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
@@ -1609,6 +1643,19 @@ public:
 	return true;
       }
   }
+  relation_kind op1_op2_relation (const irange &lhs, const frange &op1,
+				  const frange &op2) const final override
+  {
+    relation_kind ret = lt_op1_op2_relation (lhs);
+    if (ret == VREL_LT
+	&& HONOR_NANS (op1.type ())
+	&& (op1.known_isnan ()
+	    || op1.maybe_isnan ()
+	    || op2.known_isnan ()
+	    || op2.maybe_isnan ()))
+      ret = VREL_VARYING; // Should have been VREL_UNLT with NAN ops.
+    return ret;
+  }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs,
 		  const frange &op2,
@@ -1692,6 +1739,7 @@ class foperator_unordered_le : public ra
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
+  using range_operator_float::op1_op2_relation;
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
@@ -1720,6 +1768,19 @@ public:
 	return true;
       }
   }
+  relation_kind op1_op2_relation (const irange &lhs, const frange &op1,
+				  const frange &op2) const final override
+  {
+    relation_kind ret = le_op1_op2_relation (lhs);
+    if (ret == VREL_LE
+	&& HONOR_NANS (op1.type ())
+	&& (op1.known_isnan ()
+	    || op1.maybe_isnan ()
+	    || op2.known_isnan ()
+	    || op2.maybe_isnan ()))
+      ret = VREL_VARYING; // Should have been VREL_UNLE with NAN ops.
+    return ret;
+  }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
 		  relation_trio = TRIO_VARYING) const final override;
@@ -1799,6 +1860,7 @@ class foperator_unordered_gt : public ra
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
+  using range_operator_float::op1_op2_relation;
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
@@ -1827,6 +1889,19 @@ public:
 	return true;
       }
   }
+  relation_kind op1_op2_relation (const irange &lhs, const frange &op1,
+				  const frange &op2) const final override
+  {
+    relation_kind ret = gt_op1_op2_relation (lhs);
+    if (ret == VREL_GT
+	&& HONOR_NANS (op1.type ())
+	&& (op1.known_isnan ()
+	    || op1.maybe_isnan ()
+	    || op2.known_isnan ()
+	    || op2.maybe_isnan ()))
+      ret = VREL_VARYING; // Should have been VREL_UNGT with NAN ops.
+    return ret;
+  }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
 		  relation_trio = TRIO_VARYING) const final override;
@@ -1910,6 +1985,7 @@ class foperator_unordered_ge : public ra
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
+  using range_operator_float::op1_op2_relation;
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
@@ -1938,6 +2014,19 @@ public:
 	return true;
       }
   }
+  relation_kind op1_op2_relation (const irange &lhs, const frange &op1,
+				  const frange &op2) const final override
+  {
+    relation_kind ret = ge_op1_op2_relation (lhs);
+    if (ret == VREL_GE
+	&& HONOR_NANS (op1.type ())
+	&& (op1.known_isnan ()
+	    || op1.maybe_isnan ()
+	    || op2.known_isnan ()
+	    || op2.maybe_isnan ()))
+      ret = VREL_VARYING; // Should have been VREL_UNGE with NAN ops.
+    return ret;
+  }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
 		  relation_trio = TRIO_VARYING) const final override;


	Jakub


  reply	other threads:[~2023-04-12 10:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11  8:21 Jakub Jelinek
2023-04-11  8:59 ` Aldy Hernandez
2023-04-11 20:58 ` Andrew MacLeod
2023-04-12 10:33   ` Jakub Jelinek [this message]
2023-04-12 14:21     ` Jakub Jelinek
2023-04-12 16:35       ` Bernhard Reutner-Fischer
2023-04-12 16:40         ` 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=ZDaJA+nwtb3wr2SR@tucnak \
    --to=jakub@redhat.com \
    --cc=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).