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: Andrew MacLeod <amacleod@redhat.com>,
	GCC patches <gcc-patches@gcc.gnu.org>,
	Aldy Hernandez <aldyh@redhat.com>
Subject: [PATCH] range-ops: Handle undefined ranges in frange op[12]_range [PR108647]
Date: Fri,  3 Feb 2023 19:09:18 +0100	[thread overview]
Message-ID: <20230203180918.6417-1-aldyh@redhat.com> (raw)

This patch gracefully handles undefined operand ranges for the floating
point op[12]_range operators.  This is very low risk, as we would have
ICEd otherwise.

We don't have a testcase that ICEs for floating point ranges, but it's
only a matter of time.  Besides, this dovetails nicely with the integer
versions Jakub is testing.

Tested on x86-64 Linux.

OK?

gcc/ChangeLog:

	PR tree-optimization/108647
	* range-op-float.cc (foperator_lt::op1_range): Handle undefined ranges.
	(foperator_lt::op2_range): Same.
	(foperator_le::op1_range): Same.
	(foperator_le::op2_range): Same.
	(foperator_gt::op1_range): Same.
	(foperator_gt::op2_range): Same.
	(foperator_ge::op1_range): Same.
	(foperator_ge::op2_range): Same.
	(foperator_unordered_lt::op1_range): Same.
	(foperator_unordered_lt::op2_range): Same.
	(foperator_unordered_le::op1_range): Same.
	(foperator_unordered_le::op2_range): Same.
	(foperator_unordered_gt::op1_range): Same.
	(foperator_unordered_gt::op2_range): Same.
	(foperator_unordered_ge::op1_range): Same.
	(foperator_unordered_ge::op2_range): Same.
---
 gcc/range-op-float.cc | 56 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 2db83aeb2fc..ff42b95de4f 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -866,6 +866,8 @@ foperator_lt::op1_range (frange &r,
       // The TRUE side of x < NAN is unreachable.
       if (op2.known_isnan ())
 	r.set_undefined ();
+      else if (op2.undefined_p ())
+	return false;
       else if (build_lt (r, type, op2))
 	{
 	  r.clear_nan ();
@@ -901,6 +903,8 @@ foperator_lt::op2_range (frange &r,
       // The TRUE side of NAN < x is unreachable.
       if (op1.known_isnan ())
 	r.set_undefined ();
+      else if (op1.undefined_p ())
+	return false;
       else if (build_gt (r, type, op1))
 	{
 	  r.clear_nan ();
@@ -982,6 +986,8 @@ foperator_le::op1_range (frange &r,
       // The TRUE side of x <= NAN is unreachable.
       if (op2.known_isnan ())
 	r.set_undefined ();
+      else if (op2.undefined_p ())
+	return false;
       else if (build_le (r, type, op2))
 	r.clear_nan ();
       break;
@@ -1013,6 +1019,8 @@ foperator_le::op2_range (frange &r,
       // The TRUE side of NAN <= x is unreachable.
       if (op1.known_isnan ())
 	r.set_undefined ();
+      else if (op1.undefined_p ())
+	return false;
       else if (build_ge (r, type, op1))
 	r.clear_nan ();
       break;
@@ -1021,6 +1029,8 @@ foperator_le::op2_range (frange &r,
       // On the FALSE side of NAN <= x, we know nothing about x.
       if (op1.known_isnan ())
 	r.set_varying (type);
+      else if (op1.undefined_p ())
+	return false;
       else
 	build_lt (r, type, op1);
       break;
@@ -1090,6 +1100,8 @@ foperator_gt::op1_range (frange &r,
       // The TRUE side of x > NAN is unreachable.
       if (op2.known_isnan ())
 	r.set_undefined ();
+      else if (op2.undefined_p ())
+	return false;
       else if (build_gt (r, type, op2))
 	{
 	  r.clear_nan ();
@@ -1102,6 +1114,8 @@ foperator_gt::op1_range (frange &r,
       // On the FALSE side of x > NAN, we know nothing about x.
       if (op2.known_isnan ())
 	r.set_varying (type);
+      else if (op2.undefined_p ())
+	return false;
       else
 	build_le (r, type, op2);
       break;
@@ -1125,6 +1139,8 @@ foperator_gt::op2_range (frange &r,
       // The TRUE side of NAN > x is unreachable.
       if (op1.known_isnan ())
 	r.set_undefined ();
+      else if (op1.undefined_p ())
+	return false;
       else if (build_lt (r, type, op1))
 	{
 	  r.clear_nan ();
@@ -1137,6 +1153,8 @@ foperator_gt::op2_range (frange &r,
       // On The FALSE side of NAN > x, we know nothing about x.
       if (op1.known_isnan ())
 	r.set_varying (type);
+      else if (op1.undefined_p ())
+	return false;
       else
 	build_ge (r, type, op1);
       break;
@@ -1206,6 +1224,8 @@ foperator_ge::op1_range (frange &r,
       // The TRUE side of x >= NAN is unreachable.
       if (op2.known_isnan ())
 	r.set_undefined ();
+      else if (op2.undefined_p ())
+	return false;
       else if (build_ge (r, type, op2))
 	r.clear_nan ();
       break;
@@ -1214,6 +1234,8 @@ foperator_ge::op1_range (frange &r,
       // On the FALSE side of x >= NAN, we know nothing about x.
       if (op2.known_isnan ())
 	r.set_varying (type);
+      else if (op2.undefined_p ())
+	return false;
       else
 	build_lt (r, type, op2);
       break;
@@ -1236,6 +1258,8 @@ foperator_ge::op2_range (frange &r, tree type,
       // The TRUE side of NAN >= x is unreachable.
       if (op1.known_isnan ())
 	r.set_undefined ();
+      else if (op1.undefined_p ())
+	return false;
       else if (build_le (r, type, op1))
 	r.clear_nan ();
       break;
@@ -1244,6 +1268,8 @@ foperator_ge::op2_range (frange &r, tree type,
       // On the FALSE side of NAN >= x, we know nothing about x.
       if (op1.known_isnan ())
 	r.set_varying (type);
+      else if (op1.undefined_p ())
+	return false;
       else
 	build_gt (r, type, op1);
       break;
@@ -1592,6 +1618,8 @@ foperator_unordered_lt::op1_range (frange &r, tree type,
     case BRS_TRUE:
       if (op2.known_isnan ())
 	r.set_varying (type);
+      else if (op2.undefined_p ())
+	return false;
       else
 	build_lt (r, type, op2);
       break;
@@ -1601,6 +1629,8 @@ foperator_unordered_lt::op1_range (frange &r, tree type,
       // impossible for op2 to be a NAN.
       if (op2.known_isnan ())
 	r.set_undefined ();
+      else if (op2.undefined_p ())
+	return false;
       else if (build_ge (r, type, op2))
 	r.clear_nan ();
       break;
@@ -1622,6 +1652,8 @@ foperator_unordered_lt::op2_range (frange &r, tree type,
     case BRS_TRUE:
       if (op1.known_isnan ())
 	r.set_varying (type);
+      else if (op1.undefined_p ())
+	return false;
       else
 	build_gt (r, type, op1);
       break;
@@ -1631,6 +1663,8 @@ foperator_unordered_lt::op2_range (frange &r, tree type,
       // impossible for op1 to be a NAN.
       if (op1.known_isnan ())
 	r.set_undefined ();
+      else if (op1.undefined_p ())
+	return false;
       else if (build_le (r, type, op1))
 	r.clear_nan ();
       break;
@@ -1686,6 +1720,8 @@ foperator_unordered_le::op1_range (frange &r, tree type,
     case BRS_TRUE:
       if (op2.known_isnan ())
 	r.set_varying (type);
+      else if (op2.undefined_p ())
+	return false;
       else
 	build_le (r, type, op2);
       break;
@@ -1717,6 +1753,8 @@ foperator_unordered_le::op2_range (frange &r,
     case BRS_TRUE:
       if (op1.known_isnan ())
 	r.set_varying (type);
+      else if (op1.undefined_p ())
+	return false;
       else
 	build_ge (r, type, op1);
       break;
@@ -1726,6 +1764,8 @@ foperator_unordered_le::op2_range (frange &r,
       // impossible for op1 to be a NAN.
       if (op1.known_isnan ())
 	r.set_undefined ();
+      else if (op1.undefined_p ())
+	return false;
       else if (build_lt (r, type, op1))
 	r.clear_nan ();
       break;
@@ -1783,6 +1823,8 @@ foperator_unordered_gt::op1_range (frange &r,
     case BRS_TRUE:
       if (op2.known_isnan ())
 	r.set_varying (type);
+      else if (op2.undefined_p ())
+	return false;
       else
 	build_gt (r, type, op2);
       break;
@@ -1792,6 +1834,8 @@ foperator_unordered_gt::op1_range (frange &r,
       // impossible for op2 to be a NAN.
       if (op2.known_isnan ())
 	r.set_undefined ();
+      else if (op2.undefined_p ())
+	return false;
       else if (build_le (r, type, op2))
 	r.clear_nan ();
       break;
@@ -1814,6 +1858,8 @@ foperator_unordered_gt::op2_range (frange &r,
     case BRS_TRUE:
       if (op1.known_isnan ())
 	r.set_varying (type);
+      else if (op1.undefined_p ())
+	return false;
       else
 	build_lt (r, type, op1);
       break;
@@ -1823,6 +1869,8 @@ foperator_unordered_gt::op2_range (frange &r,
       // impossible for op1 to be a NAN.
       if (op1.known_isnan ())
 	r.set_undefined ();
+      else if (op1.undefined_p ())
+	return false;
       else if (build_ge (r, type, op1))
 	r.clear_nan ();
       break;
@@ -1880,6 +1928,8 @@ foperator_unordered_ge::op1_range (frange &r,
     case BRS_TRUE:
       if (op2.known_isnan ())
 	r.set_varying (type);
+      else if (op2.undefined_p ())
+	return false;
       else
 	build_ge (r, type, op2);
       break;
@@ -1889,6 +1939,8 @@ foperator_unordered_ge::op1_range (frange &r,
       // impossible for op2 to be a NAN.
       if (op2.known_isnan ())
 	r.set_undefined ();
+      else if (op2.undefined_p ())
+	return false;
       else if (build_lt (r, type, op2))
 	r.clear_nan ();
       break;
@@ -1910,6 +1962,8 @@ foperator_unordered_ge::op2_range (frange &r, tree type,
     case BRS_TRUE:
       if (op1.known_isnan ())
 	r.set_varying (type);
+      else if (op1.undefined_p ())
+	return false;
       else
 	build_le (r, type, op1);
       break;
@@ -1919,6 +1973,8 @@ foperator_unordered_ge::op2_range (frange &r, tree type,
       // impossible for op1 to be a NAN.
       if (op1.known_isnan ())
 	r.set_undefined ();
+      else if (op1.undefined_p ())
+	return false;
       else if (build_gt (r, type, op1))
 	r.clear_nan ();
       break;
-- 
2.39.1


             reply	other threads:[~2023-02-03 18:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03 18:09 Aldy Hernandez [this message]
2023-02-03 18:28 ` 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=20230203180918.6417-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).