]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
If a range's bitmask changes, reflect it in the bounds.
authorAndrew MacLeod <amacleod@redhat.com>
Thu, 2 Oct 2025 15:51:01 +0000 (11:51 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Mon, 6 Oct 2025 16:25:33 +0000 (12:25 -0400)
Rather than trying to be smart, if the bitmask changes, adjust all range
bounds to satisfy the bitmask requirements.

PR tree-optimization/121206
gcc/
* value-range.cc (irange::intersect_bitmask): Always call
set_range_from_bitmask if the bitmask changes.

gcc/testsuite
* gcc.dg/pr121987.c: New.

gcc/testsuite/gcc.dg/pr121987.c [new file with mode: 0644]
gcc/value-range.cc

diff --git a/gcc/testsuite/gcc.dg/pr121987.c b/gcc/testsuite/gcc.dg/pr121987.c
new file mode 100644 (file)
index 0000000..04845a4
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+int a, b, c, d;
+int main() {
+  unsigned long e = 10000000000;
+  unsigned f;
+  int g;
+  while (a) {
+    c = 1;
+    d = f;
+    f = ~(~(~(b && g) % a * ~e) << c);
+    b = e && f % e + ~f;
+    g = a;
+  }
+  return 0;
+}
index dc6909e77c54b4d3aa184a82851f98889203433a..d34a2623db441aed5ad2d8b1d16d98e6af931424 100644 (file)
@@ -2552,22 +2552,19 @@ irange::intersect_bitmask (const irange &r)
 {
   gcc_checking_assert (!undefined_p () && !r.undefined_p ());
 
+  // If the bitmasks are the same, do nothing.
   if (m_bitmask == r.m_bitmask)
     return false;
 
   irange_bitmask bm = get_bitmask ();
   irange_bitmask save = bm;
   bm.intersect (r.get_bitmask ());
-  // Use ths opportunity to make sure mask always reflects the
-  // best mask we have.
-  m_bitmask = bm;
 
-  // Updating m_bitmask may still yield a semantic bitmask (as
-  // returned by get_bitmask) which is functionally equivalent to what
-  // we originally had.  In which case, there's still no change.
-  if (save == bm || save == get_bitmask ())
+  // If the new mask is the same, there is no change.
+  if (m_bitmask == bm)
     return false;
 
+  m_bitmask = bm;
   if (!set_range_from_bitmask ())
     normalize_kind ();
   if (flag_checking)