Its very inefficient to create a prange from prange_storage only to
extract the bitmask. This a common request with the alignment extracted
from the bitmask now. This patch allows the bitmask to be directly
extracted from the prange_storage object.
Bootstraps on x86_64-pc-linux-gnu with no regressions. Pushed.
Andrew
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 | 15 +++++++--------
gcc/value-range-storage.cc | 36 ++++++++++++++++++++++++++++++++++++
gcc/value-range-storage.h | 1 +
3 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index d4414e261cc..565ebda14cd 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,16 +841,15 @@ 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 ())
+ prange_storage *s = ssa_name_prange_storage (name);
+ if (!s)
return false;
- bool known = bitmask_to_alignment (r.get_bitmask (), alignp, misalignp);
+ bool known = bitmask_to_alignment (s->get_bitmask (TREE_TYPE (name)),
+ alignp, misalignp);
/* 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));
diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index 35997372e7c..62879585b6d 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -883,6 +883,42 @@ 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