diff mbox series

range-ops: Handle undefined ranges in frange op[12]_range [PR108647]

Message ID 20230203180918.6417-1-aldyh@redhat.com
State New
Headers show
Series range-ops: Handle undefined ranges in frange op[12]_range [PR108647] | expand

Commit Message

Aldy Hernandez Feb. 3, 2023, 6:09 p.m. UTC
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(+)

Comments

Jakub Jelinek Feb. 3, 2023, 6:28 p.m. UTC | #1
On Fri, Feb 03, 2023 at 07:09:18PM +0100, Aldy Hernandez wrote:
> 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.

LGTM (even bootstrapped/regtested this successfully on i686-linux).

	Jakub
diff mbox series

Patch

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;