https://gcc.gnu.org/g:e4c6a0214c3ea8aa73e50b1496eb7a8aa5eda635

commit r16-662-ge4c6a0214c3ea8aa73e50b1496eb7a8aa5eda635
Author: Andrew MacLeod <amacl...@redhat.com>
Date:   Tue May 13 13:23:16 2025 -0400

    Turn get_bitmask_from_range into an irange_bitmask constructor.
    
    There are other places where this is interesting, so move the static
    function into a constructor for class irange_bitmask.
    
            * value-range.cc (irange_bitmask::irange_bitmask): Rename from
            get_bitmask_from_range and tweak.
            (prange::set): Use new constructor.
            (prange::intersect): Use new constructor.
            (irange::get_bitmask): Likewise.
            * value-range.h (irange_bitmask): New constructor prototype.

Diff:
---
 gcc/value-range.cc | 32 ++++++++++++++++----------------
 gcc/value-range.h  |  2 ++
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index d2c14e7900df..48a1521b81ec 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -31,25 +31,26 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "gimple-range.h"
 
-// Return the bitmask inherent in a range.
+// Return the bitmask inherent in a range :   TYPE [MIN, MAX].
+// This use to be get_bitmask_from_range ().
 
-static irange_bitmask
-get_bitmask_from_range (tree type,
-                       const wide_int &min, const wide_int &max)
+irange_bitmask::irange_bitmask (tree type,
+                               const wide_int &min, const wide_int &max)
 {
   unsigned prec = TYPE_PRECISION (type);
-
   // All the bits of a singleton are known.
   if (min == max)
     {
-      wide_int mask = wi::zero (prec);
-      wide_int value = min;
-      return irange_bitmask (value, mask);
+      m_mask = wi::zero (prec);
+      m_value = min;
+    }
+  else
+    {
+      wide_int xorv = min ^ max;
+      xorv = wi::mask (prec - wi::clz (xorv), false, prec);
+      m_value = wi::zero (prec);
+      m_mask = min | xorv;
     }
-
-  wide_int xorv = min ^ max;
-  xorv = wi::mask (prec - wi::clz (xorv), false, prec);
-  return irange_bitmask (wi::zero (prec), min | xorv);
 }
 
 void
@@ -469,7 +470,7 @@ prange::set (tree type, const wide_int &min, const wide_int 
&max,
     }
 
   m_kind = VR_RANGE;
-  m_bitmask = get_bitmask_from_range (type, min, max);
+  m_bitmask = irange_bitmask (type, min, max);
   if (flag_checking)
     verify_range ();
 }
@@ -583,7 +584,7 @@ prange::intersect (const vrange &v)
     }
 
   // Intersect all bitmasks: the old one, the new one, and the other operand's.
-  irange_bitmask new_bitmask = get_bitmask_from_range (m_type, m_min, m_max);
+  irange_bitmask new_bitmask (m_type, m_min, m_max);
   m_bitmask.intersect (new_bitmask);
   m_bitmask.intersect (r.m_bitmask);
   if (varying_compatible_p ())
@@ -2396,8 +2397,7 @@ irange::get_bitmask () const
   // in the mask.
   //
   // See also the note in irange_bitmask::intersect.
-  irange_bitmask bm
-    = get_bitmask_from_range (type (), lower_bound (), upper_bound ());
+  irange_bitmask bm (type (), lower_bound (), upper_bound ());
   if (!m_bitmask.unknown_p ())
     bm.intersect (m_bitmask);
   return bm;
diff --git a/gcc/value-range.h b/gcc/value-range.h
index f6942989a6f3..74cdf29ddcb3 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -136,6 +136,8 @@ public:
   irange_bitmask () { /* uninitialized */ }
   irange_bitmask (unsigned prec) { set_unknown (prec); }
   irange_bitmask (const wide_int &value, const wide_int &mask);
+  irange_bitmask (tree type, const wide_int &min, const wide_int &max);
+
   wide_int value () const { return m_value; }
   wide_int mask () const { return m_mask; }
   void set_unknown (unsigned prec);

Reply via email to