diff mbox series

[COMMITTED,prange] Drop range to VARYING if the bitmask intersection made it so [PR115131]

Message ID 20240517140346.1023791-1-aldyh@redhat.com
State New
Headers show
Series [COMMITTED,prange] Drop range to VARYING if the bitmask intersection made it so [PR115131] | expand

Commit Message

Aldy Hernandez May 17, 2024, 2:03 p.m. UTC
If the intersection of the bitmasks made the range span the entire
domain, normalize the range to VARYING.

gcc/ChangeLog:

	PR middle-end/115131
	* value-range.cc (prange::intersect): Set VARYING if intersection
	of bitmasks made the range span the entire domain.
	(range_tests_misc): New test.
---
 gcc/value-range.cc | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Mikael Morin May 27, 2024, 5:15 p.m. UTC | #1
Hello,

Le 17/05/2024 à 16:03, Aldy Hernandez a écrit :
> If the intersection of the bitmasks made the range span the entire
> domain, normalize the range to VARYING.
> 
> gcc/ChangeLog:
> 
> 	PR middle-end/115131
> 	* value-range.cc (prange::intersect): Set VARYING if intersection
> 	of bitmasks made the range span the entire domain.
> 	(range_tests_misc): New test.
> ---
>   gcc/value-range.cc | 21 +++++++++++++++++++++
>   1 file changed, 21 insertions(+)
> 
> diff --git a/gcc/value-range.cc b/gcc/value-range.cc
> index 334ffb70fbc..b38d6159a85 100644
> --- a/gcc/value-range.cc
> +++ b/gcc/value-range.cc
> @@ -589,6 +589,11 @@ prange::intersect (const vrange &v)
>     irange_bitmask new_bitmask = get_bitmask_from_range (m_type, m_min, m_max);
>     m_bitmask.intersect (new_bitmask);
>     m_bitmask.intersect (r.m_bitmask);
> +  if (varying_compatible_p ())
> +    {
> +      set_varying (type ());
> +      return true;
> +    }
>   
>     if (flag_checking)
>       verify_range ();
> @@ -2889,6 +2894,22 @@ range_tests_misc ()
>     p0.invert ();
>     ASSERT_TRUE (p0 == p1);
>   
> +  // The intersection of:
> +  //    [0, +INF] MASK 0xff..00 VALUE 0xf8
> +  //    [0, +INF] MASK 0xff..00 VALUE 0x00
> +  // is [0, +INF] MASK 0xff..ff VALUE 0x00, which is VARYING.
> +  // Test that we normalized to VARYING.
> +  unsigned prec = TYPE_PRECISION (voidp);
> +  p0.set_varying (voidp);
> +  wide_int mask = wi::mask (8, true, prec);
> +  wide_int value = wi::uhwi (0xf8, prec);
> +  irange_bitmask bm (wi::uhwi (0xf8, prec), mask);
> +  p0.update_bitmask (bm);
> +  p1.set_varying (voidp);
> +  bm = irange_bitmask (wi::zero (prec), mask);
> +  p1.update_bitmask (bm);
> +  p0.intersect (p1);

Isn't a check missing here,
   ASSERT_TRUE (p0.varying_p ())
or something?

> +
>     // [10,20] U [15, 30] => [10, 30].
>     r0 = range_int (10, 20);
>     r1 = range_int (15, 30);
diff mbox series

Patch

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 334ffb70fbc..b38d6159a85 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -589,6 +589,11 @@  prange::intersect (const vrange &v)
   irange_bitmask new_bitmask = get_bitmask_from_range (m_type, m_min, m_max);
   m_bitmask.intersect (new_bitmask);
   m_bitmask.intersect (r.m_bitmask);
+  if (varying_compatible_p ())
+    {
+      set_varying (type ());
+      return true;
+    }
 
   if (flag_checking)
     verify_range ();
@@ -2889,6 +2894,22 @@  range_tests_misc ()
   p0.invert ();
   ASSERT_TRUE (p0 == p1);
 
+  // The intersection of:
+  //    [0, +INF] MASK 0xff..00 VALUE 0xf8
+  //    [0, +INF] MASK 0xff..00 VALUE 0x00
+  // is [0, +INF] MASK 0xff..ff VALUE 0x00, which is VARYING.
+  // Test that we normalized to VARYING.
+  unsigned prec = TYPE_PRECISION (voidp);
+  p0.set_varying (voidp);
+  wide_int mask = wi::mask (8, true, prec);
+  wide_int value = wi::uhwi (0xf8, prec);
+  irange_bitmask bm (wi::uhwi (0xf8, prec), mask);
+  p0.update_bitmask (bm);
+  p1.set_varying (voidp);
+  bm = irange_bitmask (wi::zero (prec), mask);
+  p1.update_bitmask (bm);
+  p0.intersect (p1);
+
   // [10,20] U [15, 30] => [10, 30].
   r0 = range_int (10, 20);
   r1 = range_int (15, 30);