]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Improve constant bitmasks.
authorAndrew MacLeod <amacleod@redhat.com>
Wed, 14 May 2025 15:12:22 +0000 (11:12 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 15 May 2025 17:07:30 +0000 (13:07 -0400)
bitmasks for constants are created only for trailing zeros. It is no
additional work to also include leading 1's in the value that are also
known.
  before :  [5, 7]  mask 0x7 value 0x0
  after  :  [5, 7]  mask 0x3 value 0x4

PR tree-optimization/116546
* value-range.cc (irange_bitmask::irange_bitmask): Include
leading ones in the bitmask.

gcc/value-range.cc

index 48a1521b81ec12d84c1bda598f64ae0d234ca527..64d10f41168b2e2a496ebe98d2cf59d368ed69a9 100644 (file)
@@ -47,9 +47,11 @@ irange_bitmask::irange_bitmask (tree type,
   else
     {
       wide_int xorv = min ^ max;
-      xorv = wi::mask (prec - wi::clz (xorv), false, prec);
-      m_value = wi::zero (prec);
-      m_mask = min | xorv;
+      // Mask will have leading zeros for all leading bits that are
+      // common, both zeros and ones.
+      m_mask = wi::mask (prec - wi::clz (xorv), false, prec);
+      // Now set value to those bits which are known, and zero the rest.
+      m_value = ~m_mask & min;
     }
 }