public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aldyh/heads/ranger-staging)] fix legacy union and intersect to only deal with legacy.
@ 2020-09-16  3:39 Andrew Macleod
  0 siblings, 0 replies; only message in thread
From: Andrew Macleod @ 2020-09-16  3:39 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b88f85d4a61b0f09465a7e9a70912cd9f832e72f

commit b88f85d4a61b0f09465a7e9a70912cd9f832e72f
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Tue Sep 15 23:38:19 2020 -0400

    fix legacy union and intersect to only deal with legacy.

Diff:
---
 gcc/range-op.cc    | 21 +++++++++++++++++
 gcc/value-range.cc | 67 ++++++++++++++++++++++--------------------------------
 2 files changed, 48 insertions(+), 40 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index c5f511422f4..e574e976ed8 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3832,6 +3832,27 @@ range_tests ()
   r0.invert ();
   ASSERT_TRUE (r0.nonzero_p ());
 
+  // test legacy interaction
+  // r0 = ~[1,1]
+  r0 = int_range<1> (UINT (1), UINT (1), VR_ANTI_RANGE);
+  // r1 = ~[3,3]
+  r1 = int_range<1> (UINT (3), UINT (3), VR_ANTI_RANGE);
+
+  // vv = [0,0][2,2][4, MAX]
+  int_range<3> vv = r0;
+  vv.intersect (r1);
+
+  ASSERT_TRUE (vv.contains_p (UINT (2)));
+  ASSERT_TRUE (vv.num_pairs () == 3);
+
+  // create r0 as legacy [1,1]
+  r0 = int_range<1> (UINT (1), UINT (1));
+  // And union it with  [0,0][2,2][4,MAX] multi range
+  r0.union_ (vv);
+  // The result should be [0,2][4,MAX], or ~[3,3]  but it must contain 2
+  ASSERT_TRUE (r0.contains_p (UINT (2)));
+
+
   multi_precision_range_tests ();
   int_range_max_tests ();
   operator_tests ();
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 20aa4f114c9..621f1c368cb 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -1078,19 +1078,14 @@ intersect_ranges (enum value_range_kind *vr0type,
 void
 irange::legacy_intersect (irange *vr0, const irange *vr1)
 {
+  gcc_checking_assert (vr0->legacy_mode_p ());
+  gcc_checking_assert (vr1->legacy_mode_p ());
   /* If either range is VR_VARYING the other one wins.  */
   if (vr1->varying_p ())
     return;
   if (vr0->varying_p ())
     {
-      /* Avoid the full copy if we already know both sides are simple
-	 and can be trivially copied.  */
-      if (vr1->legacy_mode_p ())
-	{
-	  vr0->set (vr1->min (), vr1->max (), vr1->kind ());
-	  return;
-	}
-      *vr0 = *vr1;
+      vr0->set (vr1->min (), vr1->max (), vr1->kind ());
       return;
     }
 
@@ -1107,17 +1102,9 @@ irange::legacy_intersect (irange *vr0, const irange *vr1)
   value_range_kind vr0kind = vr0->kind ();
   tree vr0min = vr0->min ();
   tree vr0max = vr0->max ();
-  /* Handle multi-ranges that can be represented as anti-ranges.  */
-  if (!vr1->legacy_mode_p () && vr1->maybe_anti_range ())
-    {
-      int_range<3> tmp (*vr1);
-      tmp.invert ();
-      intersect_ranges (&vr0kind, &vr0min, &vr0max,
-			VR_ANTI_RANGE, tmp.min (), tmp.max ());
-    }
-  else
-    intersect_ranges (&vr0kind, &vr0min, &vr0max,
-		      vr1->kind (), vr1->min (), vr1->max ());
+
+  intersect_ranges (&vr0kind, &vr0min, &vr0max,
+		    vr1->kind (), vr1->min (), vr1->max ());
 
   /* Make sure to canonicalize the result though as the inversion of a
      VR_RANGE can still be a VR_RANGE.  */
@@ -1412,6 +1399,9 @@ give_up:
 void
 irange::legacy_union (irange *vr0, const irange *vr1)
 {
+  gcc_checking_assert (vr0->legacy_mode_p ());
+  gcc_checking_assert (vr1->legacy_mode_p ());
+
   /* VR0 has the resulting range if VR1 is undefined or VR0 is varying.  */
   if (vr1->undefined_p ()
       || vr0->varying_p ())
@@ -1420,16 +1410,10 @@ irange::legacy_union (irange *vr0, const irange *vr1)
   /* VR1 has the resulting range if VR0 is undefined or VR1 is varying.  */
   if (vr0->undefined_p ())
     {
-      /* Avoid the full copy if we already know both sides are simple
-	 and can be trivially copied.  */
-      if (vr1->legacy_mode_p ())
-	{
-	  vr0->set (vr1->min (), vr1->max (), vr1->kind ());
-	  return;
-	}
-      *vr0 = *vr1;
+      vr0->set (vr1->min (), vr1->max (), vr1->kind ());
       return;
     }
+
   if (vr1->varying_p ())
     {
       vr0->set_varying (vr1->type ());
@@ -1439,17 +1423,9 @@ irange::legacy_union (irange *vr0, const irange *vr1)
   value_range_kind vr0kind = vr0->kind ();
   tree vr0min = vr0->min ();
   tree vr0max = vr0->max ();
-  /* Handle multi-ranges that can be represented as anti-ranges.  */
-  if (!vr1->legacy_mode_p () && vr1->maybe_anti_range ())
-    {
-      int_range<3> tmp (*vr1);
-      tmp.invert ();
-      union_ranges (&vr0kind, &vr0min, &vr0max,
-		    VR_ANTI_RANGE, tmp.min (), tmp.max ());
-    }
-  else
-    union_ranges (&vr0kind, &vr0min, &vr0max,
-		  vr1->kind (), vr1->min (), vr1->max ());
+
+  union_ranges (&vr0kind, &vr0min, &vr0max,
+		vr1->kind (), vr1->min (), vr1->max ());
 
   if (vr0kind == VR_UNDEFINED)
     vr0->set_undefined ();
@@ -1477,6 +1453,12 @@ irange::union_ (const irange *other)
 {
   if (legacy_mode_p ())
     {
+      if (!other->legacy_mode_p ())
+        {
+	  int_range<1> tmp = *other;
+	  legacy_union (this, &tmp);
+	  return;
+	}
       if (dump_file && (dump_flags & TDF_DETAILS))
 	{
 	  fprintf (dump_file, "Meeting\n  ");
@@ -1499,8 +1481,7 @@ irange::union_ (const irange *other)
 
   if (other->legacy_mode_p ())
     {
-      int_range<2> wider;
-      wider = *other;
+      int_range<2> wider = *other;
       irange_union (wider);
     }
   else
@@ -1512,6 +1493,12 @@ irange::intersect (const irange *other)
 {
   if (legacy_mode_p ())
     {
+      if (!other->legacy_mode_p ())
+        {
+	  int_range<1> tmp = *other;
+	  legacy_intersect (this, &tmp);
+	  return;
+	}
       if (dump_file && (dump_flags & TDF_DETAILS))
 	{
 	  fprintf (dump_file, "Intersecting\n  ");


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-16  3:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16  3:39 [gcc(refs/users/aldyh/heads/ranger-staging)] fix legacy union and intersect to only deal with legacy Andrew Macleod

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).