]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use non-null knowledge in path_range_query.
authorAldy Hernandez <aldyh@redhat.com>
Fri, 3 Sep 2021 09:22:26 +0000 (11:22 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Fri, 3 Sep 2021 13:30:57 +0000 (15:30 +0200)
This patch improves ranges for pointers we are interested in a path, by
using the non-null class from the ranger.  This allows us to thread more
paths with minimal effort.

Tested on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-path.cc (path_range_query::range_defined_in_block):
Adjust for non-null.
(path_range_query::adjust_for_non_null_uses): New.
(path_range_query::precompute_ranges): Call
adjust_for_non_null_uses.
* gimple-range-path.h: Add m_non_null and
adjust_for_non_null_uses.

gcc/gimple-range-path.cc
gcc/gimple-range-path.h

index 6d6e5eb66354725da126749feee60c12bfb91275..db15eb3ff22729cad3dfb5518fd048a06752d9c9 100644 (file)
@@ -221,6 +221,9 @@ path_range_query::range_defined_in_block (irange &r, tree name, basic_block bb)
   else if (!fold_range (r, def_stmt, this))
     r.set_varying (TREE_TYPE (name));
 
+  if (bb)
+    m_non_null.adjust_range (r, name, bb);
+
   if (DEBUG_SOLVER && (bb || !r.varying_p ()))
     {
       fprintf (dump_file, "range_defined_in_block (BB%d) for ", bb ? bb->index : -1);
@@ -302,6 +305,35 @@ path_range_query::precompute_ranges_in_block (basic_block bb)
     }
 }
 
+// Adjust all pointer imports in BB with non-null information.
+
+void
+path_range_query::adjust_for_non_null_uses (basic_block bb)
+{
+  int_range_max r;
+  bitmap_iterator bi;
+  unsigned i;
+
+  EXECUTE_IF_SET_IN_BITMAP (m_imports, 0, i, bi)
+    {
+      tree name = ssa_name (i);
+
+      if (!POINTER_TYPE_P (TREE_TYPE (name)))
+       continue;
+
+      if (get_cache (r, name))
+       {
+         if (r.nonzero_p ())
+           continue;
+       }
+      else
+       r.set_varying (TREE_TYPE (name));
+
+      if (m_non_null.adjust_range (r, name, bb))
+       set_cache (r, name);
+    }
+}
+
 // Precompute the ranges for IMPORTS along PATH.
 //
 // IMPORTS are the set of SSA names, any of which could potentially
@@ -332,6 +364,7 @@ path_range_query::precompute_ranges (const vec<basic_block> &path,
       basic_block bb = curr_bb ();
 
       precompute_ranges_in_block (bb);
+      adjust_for_non_null_uses (bb);
 
       if (at_exit ())
        break;
index 0d2d2e7f75d21c62cf6812dc69133ca64c0551e5..5177313104020ee7288696902f574c639ce2ba0c 100644 (file)
@@ -53,6 +53,7 @@ private:
   // Methods to precompute ranges for the given path.
   bool range_defined_in_block (irange &, tree name, basic_block bb);
   void precompute_ranges_in_block (basic_block bb);
+  void adjust_for_non_null_uses (basic_block bb);
   void ssa_range_in_phi (irange &r, gphi *phi);
 
   // Path navigation.
@@ -80,6 +81,7 @@ private:
 
   const bitmap_head *m_imports;
   gimple_ranger &m_ranger;
+  non_null_ref m_non_null;
 };
 
 #endif // GCC_TREE_SSA_THREADSOLVER_H