aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2020-10-05 17:36:13 +0200
committerAldy Hernandez <aldyh@redhat.com>2020-10-05 19:51:36 +0200
commitea6da7f50fe2adc3a09fc10a3f437902c40ebff9 (patch)
tree9cdf2c422cb3bf145fd43b138b734bcd4b2a2dd9
parentbd431d26de02180d7fac1a794e2b9d3aaa4df34d (diff)
downloadgcc-ea6da7f50fe2adc3a09fc10a3f437902c40ebff9.zip
gcc-ea6da7f50fe2adc3a09fc10a3f437902c40ebff9.tar.gz
gcc-ea6da7f50fe2adc3a09fc10a3f437902c40ebff9.tar.bz2
Cleanup legacy_union and legacy intersect in value_range.
These are cleanups so that multi-range union/intersect doesn't have to deal with legacy code. Instead, these should be done in legacy mode. gcc/ChangeLog: * value-range.cc (irange::legacy_intersect): Only handle legacy ranges. (irange::legacy_union): Same. (irange::union_): When unioning legacy with non-legacy, first convert to legacy and do everything in legacy mode. (irange::intersect): Same, but for intersect. * range-op.cc (range_tests): Adjust for above changes.
-rw-r--r--gcc/range-op.cc21
-rw-r--r--gcc/value-range.cc67
2 files changed, 48 insertions, 40 deletions
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 11e847f..87c6d82 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3901,6 +3901,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 ed2c322..cdcc6c6 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -1093,19 +1093,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;
}
@@ -1122,17 +1117,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. */
@@ -1427,6 +1414,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 ())
@@ -1435,16 +1425,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 ());
@@ -1454,17 +1438,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 ();
@@ -1492,6 +1468,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 ");
@@ -1514,8 +1496,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
@@ -1527,6 +1508,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 ");