known_nonzero_bits for pointers was simply returning 0, completely ignoring the 
existence of a bitmask and alignment info.  This corrects that situation and 
handles pointers properly now that they have a bitmask.

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

Andrew


        * tree-ssanames.cc (get_known_nonzero_bits_1): Handle pointers.
        * value-range-storage.h (prange_storage::undefined_p): New.
---
 gcc/tree-ssanames.cc      | 18 ++++++++++++++++--
 gcc/value-range-storage.h |  1 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 46ae07a49a9..061524a9e3d 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -645,10 +645,24 @@ get_known_nonzero_bits_1 (const_tree name)
   /* Use element_precision instead of TYPE_PRECISION so complex and
      vector types get a non-zero precision.  */
   unsigned int precision = element_precision (TREE_TYPE (name));
-  if (TREE_CODE (name) != SSA_NAME || POINTER_TYPE_P (TREE_TYPE (name)))
+  if (TREE_CODE (name) != SSA_NAME)
     return wi::shwi (0, precision);
 
-  if (!SSA_NAME_RANGE_INFO (name) || !irange::supports_p (TREE_TYPE (name)))
+  if (!SSA_NAME_RANGE_INFO (name))
+    return wi::shwi (0, precision);
+
+  // Known pointer bits, including alignment, are encoded in the bitmask
+  if (POINTER_TYPE_P (TREE_TYPE (name)))
+    {
+      prange_storage *s = ssa_name_prange_storage (name);
+      gcc_checking_assert (s);
+      if (s->undefined_p ())
+       return wi::shwi (0, precision);
+      irange_bitmask bm = s->get_bitmask (TREE_TYPE (name));
+      return wi::bit_and_not (bm.value (), bm.mask ());
+    }
+
+  if (!irange::supports_p (TREE_TYPE (name)))
     return wi::shwi (0, precision);
 
   int_range_max tmp;
diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h
index b797cb83ce2..81d47ec5e51 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;
+  bool undefined_p () const { return m_kind == PR_UNDEFINED; }
   irange_bitmask get_bitmask (tree type) const;
   bool nonnull_p (tree type) const;
   void set_nonnull (tree type);
-- 
2.56.0

Reply via email to