This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[COMMITTED] Remove range_intersect, range_invert, and range_union.


range_intersect, range_union, and range_intersect are currently returning their results by value. After Andrew's change, these should also return their results in an argument. However, if we do this, the functions become superfluous since we have corresponding API methods with the same functionality:

-      r = range_intersect (op1, op2);
+      r = op1;
+      r.intersect (op2);

I have removed all 3 functions and have adjusted the code throughout.

Committed as mostly obvious, after having consulted with Andrew that it was these and not the range_true* ones as well that needed adjusting.

Aldy
commit e0f55e7de91f779fe12ab65fc9479e4df0fe2614
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Thu Nov 14 17:55:32 2019 +0100

    Remove range_intersect, range_invert, and range_union.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 051b10ed953..4266f6b1655 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,16 @@
+2019-11-14  Aldy Hernandez  <aldyh@redhat.com>
+
+	* range-op.cc (*operator*::*range): Remove calls to
+	range_intersect, range_invert, and range_union in favor of calling
+	the in-place API methods.
+	(range_tests): Same.
+	* range.cc (range_intersect): Remove.
+	(range_union): Remove.
+	(range_invert): Remove.
+	* range.h (range_intersect): Remove.
+	(range_union): Remove.
+	(range_intersect): Remove.
+
 2019-11-14  Ilya Leoshkevich  <iii@linux.ibm.com>
 
 	PR rtl-optimization/92430
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index ae3025c6eea..4a23cca3dbb 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -396,7 +396,8 @@ operator_equal::fold_range (value_range &r, tree type,
     {
       // If ranges do not intersect, we know the range is not equal,
       // otherwise we don't know anything for sure.
-      r = range_intersect (op1, op2);
+      r = op1;
+      r.intersect (op2);
       if (r.undefined_p ())
 	r = range_false (type);
       else
@@ -415,7 +416,10 @@ operator_equal::op1_range (value_range &r, tree type,
       // If the result is false, the only time we know anything is
       // if OP2 is a constant.
       if (wi::eq_p (op2.lower_bound(), op2.upper_bound()))
-	r = range_invert (op2);
+	{
+	  r = op2;
+	  r.invert ();
+	}
       else
 	r.set_varying (type);
       break;
@@ -476,7 +480,8 @@ operator_not_equal::fold_range (value_range &r, tree type,
     {
       // If ranges do not intersect, we know the range is not equal,
       // otherwise we don't know anything for sure.
-      r = range_intersect (op1, op2);
+      r = op1;
+      r.intersect (op2);
       if (r.undefined_p ())
 	r = range_true (type);
       else
@@ -495,7 +500,10 @@ operator_not_equal::op1_range (value_range &r, tree type,
       // If the result is true, the only time we know anything is if
       // OP2 is a constant.
       if (wi::eq_p (op2.lower_bound(), op2.upper_bound()))
-	r = range_invert (op2);
+	{
+	  r = op2;
+	  r.invert ();
+	}
       else
 	r.set_varying (type);
       break;
@@ -1974,7 +1982,8 @@ operator_logical_or::fold_range (value_range &r, tree type ATTRIBUTE_UNUSED,
   if (empty_range_check (r, lh, rh))
     return;
 
-  r = range_union (lh, rh);
+  r = lh;
+  r.union_ (rh);
 }
 
 bool
@@ -2221,7 +2230,10 @@ operator_logical_not::fold_range (value_range &r, tree type,
   if (lh.varying_p () || lh.undefined_p ())
     r = lh;
   else
-    r = range_invert (lh);
+    {
+      r = lh;
+      r.invert ();
+    }
   gcc_checking_assert (lh.type() == type);
   return;
 }
@@ -2232,10 +2244,9 @@ operator_logical_not::op1_range (value_range &r,
 				 const value_range &lhs,
 				 const value_range &op2 ATTRIBUTE_UNUSED) const
 {
-  if (lhs.varying_p () || lhs.undefined_p ())
-    r = lhs;
-  else
-    r = range_invert (lhs);
+  r = lhs;
+  if (!lhs.varying_p () && !lhs.undefined_p ())
+    r.invert ();
   return true;
 }
 
@@ -3033,13 +3044,6 @@ range_tests ()
   r1.union_ (r2);
   ASSERT_TRUE (r0 == r1);
 
-  // [10,20] U [30,40] ==> [10,20][30,40].
-  r0 = value_range (INT (10), INT (20));
-  r1 = value_range (INT (30), INT (40));
-  r0.union_ (r1);
-  ASSERT_TRUE (r0 == range_union (value_range (INT (10), INT (20)),
-				  value_range (INT (30), INT (40))));
-
   // Make sure NULL and non-NULL of pointer types work, and that
   // inverses of them are consistent.
   tree voidp = build_pointer_type (void_type_node);
@@ -3049,27 +3053,12 @@ range_tests ()
   r0.invert ();
   ASSERT_TRUE (r0 == r1);
 
-  // [10,20][30,40] U [25,70] => [10,70].
-  r0 = range_union (value_range (INT (10), INT (20)),
-		     value_range (INT (30), INT (40)));
-  r1 = value_range (INT (25), INT (70));
-  r0.union_ (r1);
-  ASSERT_TRUE (r0 == range_union (value_range (INT (10), INT (20)),
-				  value_range (INT (25), INT (70))));
-
   // [10,20] U [15, 30] => [10, 30].
   r0 = value_range (INT (10), INT (20));
   r1 = value_range (INT (15), INT (30));
   r0.union_ (r1);
   ASSERT_TRUE (r0 == value_range (INT (10), INT (30)));
 
-  // [10,20] U [25,25] => [10,20][25,25].
-  r0 = value_range (INT (10), INT (20));
-  r1 = value_range (INT (25), INT (25));
-  r0.union_ (r1);
-  ASSERT_TRUE (r0 == range_union (value_range (INT (10), INT (20)),
-				  value_range (INT (25), INT (25))));
-
   // [15,40] U [] => [15,40].
   r0 = value_range (INT (15), INT (40));
   r1.set_undefined ();
@@ -3094,19 +3083,6 @@ range_tests ()
   r0.intersect (r1);
   ASSERT_TRUE (r0 == value_range (INT (15), INT (20)));
 
-  // [10,20][30,40] ^ [40,50] => [40,40].
-  r0 = range_union (value_range (INT (10), INT (20)),
-		     value_range (INT (30), INT (40)));
-  r1 = value_range (INT (40), INT (50));
-  r0.intersect (r1);
-  ASSERT_TRUE (r0 == value_range (INT (40), INT (40)));
-
-  // Test non-destructive intersection.
-  r0 = rold = value_range (INT (10), INT (20));
-  ASSERT_FALSE (range_intersect (r0, value_range (INT (15),
-					     INT (30))).undefined_p ());
-  ASSERT_TRUE (r0 == rold);
-
   // Test the internal sanity of wide_int's wrt HWIs.
   ASSERT_TRUE (wi::max_value (TYPE_PRECISION (boolean_type_node),
 			      TYPE_SIGN (boolean_type_node))
diff --git a/gcc/range.cc b/gcc/range.cc
index e592d05738e..6eff6c0a38f 100644
--- a/gcc/range.cc
+++ b/gcc/range.cc
@@ -29,30 +29,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "ssa.h"
 #include "range.h"
 
-value_range
-range_intersect (const value_range &r1, const value_range &r2)
-{
-  value_range tmp (r1);
-  tmp.intersect (r2);
-  return tmp;
-}
-
-value_range
-range_invert (const value_range &r1)
-{
-  value_range tmp (r1);
-  tmp.invert ();
-  return tmp;
-}
-
-value_range
-range_union (const value_range &r1, const value_range &r2)
-{
-  value_range tmp (r1);
-  tmp.union_ (r2);
-  return tmp;
-}
-
 value_range
 range_zero (tree type)
 {
diff --git a/gcc/range.h b/gcc/range.h
index b4806e64bbb..6efec1699e3 100644
--- a/gcc/range.h
+++ b/gcc/range.h
@@ -23,9 +23,6 @@ along with GCC; see the file COPYING3.  If not see
 
 value_range range_zero (tree type);
 value_range range_nonzero (tree type);
-value_range range_intersect (const value_range &, const value_range &);
-value_range range_union (const value_range &, const value_range &);
-value_range range_invert (const value_range &);
 value_range range_positives (tree type);
 value_range range_negatives (tree type);
 #endif // GCC_RANGE_H

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]