public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] [prange] Drop range to VARYING if the bitmask intersection made it so [PR115131]
@ 2024-05-17 14:03 Aldy Hernandez
  2024-05-27 17:15 ` Mikael Morin
  0 siblings, 1 reply; 2+ messages in thread
From: Aldy Hernandez @ 2024-05-17 14:03 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

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);
+
   // [10,20] U [15, 30] => [10, 30].
   r0 = range_int (10, 20);
   r1 = range_int (15, 30);
-- 
2.45.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [COMMITTED] [prange] Drop range to VARYING if the bitmask intersection made it so [PR115131]
  2024-05-17 14:03 [COMMITTED] [prange] Drop range to VARYING if the bitmask intersection made it so [PR115131] Aldy Hernandez
@ 2024-05-27 17:15 ` Mikael Morin
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2024-05-27 17:15 UTC (permalink / raw)
  To: Aldy Hernandez, GCC patches; +Cc: Andrew MacLeod

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-27 17:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-17 14:03 [COMMITTED] [prange] Drop range to VARYING if the bitmask intersection made it so [PR115131] Aldy Hernandez
2024-05-27 17:15 ` Mikael Morin

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