THe introduction of using a bitmask for alignment info caused a minor performance impact, mostly from constructing a prange simply to extract the bitmask...   This is alleviated by adding a get_bitmask() routine to a prange_storage, bypassing all the extra work.

Bootstraps with no regressions on x86_64-pc-linux-gnu.  OK for trunk?

Andrew


From d81fdccc5fea8939246f0caf3243162a109d5684 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <[email protected]>
Date: Sat, 24 Oct 2026 11:05:47 -0400
Subject: [PATCH 9/9] Add get_bitmask to prange_storage

Extract a bitmask directly from a prange_storage.  This is far more efficient
than constructing a prange in order to extract it.

	* tree-ssanames.cc (get_nonzero_bits_1): Call get_bitmask directly
	from a prange_storage.
	(get_ptr_info_alignment): Likewise.
	* value-range-storage.cc (prange_storage::get_bitmask): New.
	* value-range-storage.h (prange_storage::get_bitmask): New prototype.
---
 gcc/tree-ssanames.cc       | 22 ++++++++--------------
 gcc/value-range-storage.cc | 37 +++++++++++++++++++++++++++++++++++++
 gcc/value-range-storage.h  |  1 +
 3 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index d4414e261cc..6b92c08d6b3 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -589,9 +589,9 @@ get_nonzero_bits_1 (const_tree name)
   // need to extract the bitmask like integers do.
   if (POINTER_TYPE_P (TREE_TYPE (name)))
     {
-      prange tmp;
-      range_info_get_range (name, tmp);
-      return tmp.get_bitmask ().get_nonzero_bits ();
+      prange_storage *s = ssa_name_prange_storage (name);
+      gcc_checking_assert (s);
+      return s->get_bitmask (TREE_TYPE (name)).get_nonzero_bits ();
     }
 
   if (!irange::supports_p (TREE_TYPE (name)))
@@ -841,19 +841,13 @@ get_ptr_info_alignment (const_tree name, unsigned int *alignp,
   if (!POINTER_TYPE_P (TREE_TYPE (name)) || !SSA_NAME_RANGE_INFO (name))
     return false;
 
-  prange r;
-  range_info_get_range (name, r);
-  if (r.undefined_p ())
-    return false;
+  prange_storage *s = ssa_name_prange_storage (name);
 
-  bool known = bitmask_to_alignment (r.get_bitmask (), alignp, misalignp);
+  if (!s)
+    return false;
 
-  /* Legacy fields may know less, but useful alignment must be implied
-     by the bitmask.  Alignment one carries no information.  */
-  prange_storage *s = ssa_name_prange_storage (name);
-  gcc_checking_assert (s->align <= 1
-		       || (known && *alignp >= s->align
-			   && (*misalignp & (s->align - 1)) == s->misalign));
+  bool known = bitmask_to_alignment (s->get_bitmask (TREE_TYPE (name)),
+				     alignp, misalignp);
   return known;
 }
 
diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index 35997372e7c..6a3d56fa49e 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -883,6 +883,43 @@ prange_storage::fits_p (const prange &r) const
   return num_words <= m_trailing_ints.num_elements ();
 }
 
+irange_bitmask
+prange_storage::get_bitmask (tree type) const
+{
+  gcc_checking_assert (m_kind != PR_UNDEFINED);
+  unsigned prec = TYPE_PRECISION (type);
+  unsigned index = 0;
+
+  switch (m_kind)
+    {
+
+      case PR_VARYING:
+	return irange_bitmask (prec);
+
+      case PR_ZERO:
+	return irange_bitmask (type, wi::zero (prec), wi::zero (prec));
+
+      case PR_NONZERO:
+      case PR_FULL:
+	break;
+
+      case PR_OTHER:
+	index = 2;
+	break;
+
+      default:
+	gcc_unreachable ();
+    }
+
+  if (m_has_bitmask)
+    {
+      wide_int value = get_word (index++, type);
+      wide_int mask = get_word (index++, type);
+      return irange_bitmask (value, mask);
+    }
+  return irange_bitmask (prec);
+}
+
 
 static vrange_allocator ggc_vrange_allocator (true);
 
diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h
index f4c264d5ede..a3a2821a445 100644
--- a/gcc/value-range-storage.h
+++ b/gcc/value-range-storage.h
@@ -131,6 +131,7 @@ public:
   void get_prange (prange &r, tree type) const;
   bool equal_p (const prange &r) const;
   bool fits_p (const prange &r) const;
+  irange_bitmask get_bitmask (tree type) const;
   void dump () const;
 
   // The points-to solution for the SSA name is flow insensitive and is
-- 
2.56.0

Reply via email to