]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[prange] Drop range to VARYING if the bitmask intersection made it so [PR115131]
authorAldy Hernandez <aldyh@redhat.com>
Fri, 17 May 2024 11:44:08 +0000 (13:44 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Fri, 17 May 2024 14:03:17 +0000 (16:03 +0200)
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

index 334ffb70fbc2c8d01491d36bf73e701820a98809..b38d6159a856919dffbfd3e9a6aba688f09bf39e 100644 (file)
@@ -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);