public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: Andrew MacLeod <amacleod@redhat.com>
Cc: GCC patches <gcc-patches@gcc.gnu.org>,
	Jeff Law <jeffreyalaw@gmail.com>,
	Aldy Hernandez <aldyh@redhat.com>
Subject: [PATCH 6/7] path solver: Add related SSAs to solvable set.
Date: Tue, 21 Sep 2021 18:53:49 +0200	[thread overview]
Message-ID: <20210921165350.414593-7-aldyh@redhat.com> (raw)
In-Reply-To: <20210921165350.414593-1-aldyh@redhat.com>

The path solver takes an initial set of SSA names which are deemed
interesting.  These are then solved along the path.  Adding any copies
of said SSA names to the list of interesting names yields significantly
better results.  This patch adds said copies to the already provided
list.

Currently this code is guarded by "m_resolve", which is the more
expensive mode, but it would be reasonable to make it available always,
especially since adding more imports usually has minimal impact on the
processing time.  I will investigate and make it universally available
if this is indeed the case.

Committed.

gcc/ChangeLog:

	* gimple-range-path.cc (path_range_query::add_to_imports): New.
	(path_range_query::add_copies_to_imports): New.
	(path_range_query::precompute_ranges): Call
	add_copies_to_imports.
	* gimple-range-path.h (class path_range_query): Add prototypes
	for add_copies_to_imports and add_to_imports.
---
 gcc/gimple-range-path.cc | 80 +++++++++++++++++++++++++++++++++++++++-
 gcc/gimple-range-path.h  |  4 +-
 2 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
index b86a76fa74b..a8ead3da4dc 100644
--- a/gcc/gimple-range-path.cc
+++ b/gcc/gimple-range-path.cc
@@ -343,6 +343,71 @@ path_range_query::adjust_for_non_null_uses (basic_block bb)
     }
 }
 
+// If NAME is a supported SSA_NAME, add it the bitmap in IMPORTS.
+
+bool
+path_range_query::add_to_imports (tree name, bitmap imports)
+{
+  if (TREE_CODE (name) == SSA_NAME
+      && irange::supports_type_p (TREE_TYPE (name)))
+    return bitmap_set_bit (imports, SSA_NAME_VERSION (name));
+  return false;
+}
+
+// Add the copies of any SSA names in IMPORTS to IMPORTS.
+//
+// These are hints for the solver.  Adding more elements (within
+// reason) doesn't slow us down, because we don't solve anything that
+// doesn't appear in the path.  On the other hand, not having enough
+// imports will limit what we can solve.
+
+void
+path_range_query::add_copies_to_imports ()
+{
+  auto_vec<tree> worklist (bitmap_count_bits (m_imports));
+  bitmap_iterator bi;
+  unsigned i;
+
+  EXECUTE_IF_SET_IN_BITMAP (m_imports, 0, i, bi)
+    {
+      tree name = ssa_name (i);
+      worklist.quick_push (name);
+    }
+
+  while (!worklist.is_empty ())
+    {
+      tree name = worklist.pop ();
+      gimple *def_stmt = SSA_NAME_DEF_STMT (name);
+
+      if (is_gimple_assign (def_stmt))
+	{
+	  // ?? Adding assignment copies doesn't get us much.  At the
+	  // time of writing, we got 63 more threaded paths across the
+	  // .ii files from a bootstrap.
+	  add_to_imports (gimple_assign_rhs1 (def_stmt), m_imports);
+	  tree rhs = gimple_assign_rhs2 (def_stmt);
+	  if (rhs && add_to_imports (rhs, m_imports))
+	    worklist.safe_push (rhs);
+	  rhs = gimple_assign_rhs3 (def_stmt);
+	  if (rhs && add_to_imports (rhs, m_imports))
+	    worklist.safe_push (rhs);
+	}
+      else if (gphi *phi = dyn_cast <gphi *> (def_stmt))
+	{
+	  for (size_t i = 0; i < gimple_phi_num_args (phi); ++i)
+	    {
+	      edge e = gimple_phi_arg_edge (phi, i);
+	      tree arg = gimple_phi_arg (phi, i)->def;
+
+	      if (TREE_CODE (arg) == SSA_NAME
+		  && m_path->contains (e->src)
+		  && bitmap_set_bit (m_imports, SSA_NAME_VERSION (arg)))
+		worklist.safe_push (arg);
+	    }
+	}
+    }
+}
+
 // Precompute the ranges for IMPORTS along PATH.
 //
 // IMPORTS are the set of SSA names, any of which could potentially
@@ -353,11 +418,12 @@ path_range_query::precompute_ranges (const vec<basic_block> &path,
 				     const bitmap_head *imports)
 {
   set_path (path);
-  m_imports = imports;
+  bitmap_copy (m_imports, imports);
   m_undefined_path = false;
 
   if (m_resolve)
     {
+      add_copies_to_imports ();
       m_oracle->reset_path ();
       precompute_relations (path);
     }
@@ -379,6 +445,18 @@ path_range_query::precompute_ranges (const vec<basic_block> &path,
     {
       basic_block bb = curr_bb ();
 
+      if (m_resolve)
+	{
+	  gori_compute &gori = m_ranger.gori ();
+	  tree name;
+
+	  // Exported booleans along the path, may help conditionals.
+	  // Add them as interesting imports.
+	  FOR_EACH_GORI_EXPORT_NAME (gori, bb, name)
+	    if (TREE_CODE (TREE_TYPE (name)) == BOOLEAN_TYPE)
+	      bitmap_set_bit (m_imports, SSA_NAME_VERSION (name));
+	}
+
       precompute_ranges_in_block (bb);
       adjust_for_non_null_uses (bb);
 
diff --git a/gcc/gimple-range-path.h b/gcc/gimple-range-path.h
index d12fd7743ca..f23cce18391 100644
--- a/gcc/gimple-range-path.h
+++ b/gcc/gimple-range-path.h
@@ -61,6 +61,8 @@ private:
   void ssa_range_in_phi (irange &r, gphi *phi);
   void precompute_relations (const vec<basic_block> &);
   void precompute_phi_relations (basic_block bb, basic_block prev);
+  void add_copies_to_imports ();
+  bool add_to_imports (tree name, bitmap imports);
 
   // Path navigation.
   void set_path (const vec<basic_block> &);
@@ -82,7 +84,7 @@ private:
   // Path being analyzed.
   const vec<basic_block> *m_path;
 
-  const bitmap_head *m_imports;
+  auto_bitmap m_imports;
   gimple_ranger &m_ranger;
   non_null_ref m_non_null;
   path_oracle *m_oracle;
-- 
2.31.1


  parent reply	other threads:[~2021-09-21 16:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-21 16:53 [PATCH 0/7] Add ability to resolve unknowns to path solver Aldy Hernandez
2021-09-21 16:53 ` [PATCH 1/7] Allocate non_null_ref tables at creation Aldy Hernandez
2021-09-21 16:53 ` [PATCH 2/7] Do not query SCEV in range_of_phi unless dominators are available Aldy Hernandez
2021-09-21 17:05   ` Andrew MacLeod
2021-09-21 17:16     ` Aldy Hernandez
2021-09-22  8:05       ` Richard Biener
2021-09-23 11:07         ` Aldy Hernandez
2021-09-21 16:53 ` [PATCH 3/7] Move postfold_gcond_edges into fur_source Aldy Hernandez
2021-09-21 16:53 ` [PATCH 4/7] path solver: Add relation support Aldy Hernandez
2021-09-21 16:53 ` [PATCH 5/7] path solver: Remove useless code Aldy Hernandez
2021-09-21 16:53 ` Aldy Hernandez [this message]
2021-09-21 16:53 ` [PATCH 7/7] path solver: Use ranger to solve unknowns Aldy Hernandez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210921165350.414593-7-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).