diff mbox series

tree-optimization/116083 - improve behavior when SLP discovery limit is reached

Message ID 20240725131417.45D4C13874@imap1.dmz-prg2.suse.org
State New
Headers show
Series tree-optimization/116083 - improve behavior when SLP discovery limit is reached | expand

Commit Message

Richard Biener July 25, 2024, 1:14 p.m. UTC
The following avoids some useless work when the SLP discovery limit
is reached, for example allocating a node to cache the failure
and starting discovery on split store groups when analyzing BBs.

It does not address the issue in the PR which is a gratious budget
for discovery when the store group size approaches the number of
overall statements.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/116083
	* tree-vect-slp.cc (vect_build_slp_tree): Do not allocate
	a discovery fail node when we reached the discovery limit.
	(vect_build_slp_instance): Terminate early when the
	discovery limit is reached.
---
 gcc/tree-vect-slp.cc | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 8c7dfc4feca..7da5853adf6 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -1756,13 +1756,6 @@  vect_build_slp_tree (vec_info *vinfo,
       return NULL;
     }
 
-  /* Seed the bst_map with a stub node to be filled by vect_build_slp_tree_2
-     so we can pick up backedge destinations during discovery.  */
-  slp_tree res = new _slp_tree;
-  SLP_TREE_DEF_TYPE (res) = vect_internal_def;
-  SLP_TREE_SCALAR_STMTS (res) = stmts;
-  bst_map->put (stmts.copy (), res);
-
   /* Single-lane SLP doesn't have the chance of run-away, do not account
      it to the limit.  */
   if (stmts.length () > 1)
@@ -1772,18 +1765,19 @@  vect_build_slp_tree (vec_info *vinfo,
 	  if (dump_enabled_p ())
 	    dump_printf_loc (MSG_NOTE, vect_location,
 			     "SLP discovery limit exceeded\n");
-	  /* Mark the node invalid so we can detect those when still in use
-	     as backedge destinations.  */
-	  SLP_TREE_SCALAR_STMTS (res) = vNULL;
-	  SLP_TREE_DEF_TYPE (res) = vect_uninitialized_def;
-	  res->failed = XNEWVEC (bool, group_size);
-	  memset (res->failed, 0, sizeof (bool) * group_size);
 	  memset (matches, 0, sizeof (bool) * group_size);
 	  return NULL;
 	}
       --*limit;
     }
 
+  /* Seed the bst_map with a stub node to be filled by vect_build_slp_tree_2
+     so we can pick up backedge destinations during discovery.  */
+  slp_tree res = new _slp_tree;
+  SLP_TREE_DEF_TYPE (res) = vect_internal_def;
+  SLP_TREE_SCALAR_STMTS (res) = stmts;
+  bst_map->put (stmts.copy (), res);
+
   if (dump_enabled_p ())
     dump_printf_loc (MSG_NOTE, vect_location,
 		     "starting SLP discovery for node %p\n", (void *) res);
@@ -3368,6 +3362,10 @@  vect_build_slp_instance (vec_info *vinfo,
 			 /* ???  We need stmt_info for group splitting.  */
 			 stmt_vec_info stmt_info_)
 {
+  /* If there's no budget left bail out early.  */
+  if (*limit == 0)
+    return false;
+
   if (kind == slp_inst_kind_ctor)
     {
       if (dump_enabled_p ())
@@ -3525,7 +3523,7 @@  vect_build_slp_instance (vec_info *vinfo,
 
   stmt_vec_info stmt_info = stmt_info_;
   /* Try to break the group up into pieces.  */
-  if (kind == slp_inst_kind_store)
+  if (*limit > 0 && kind == slp_inst_kind_store)
     {
       /* ???  We could delay all the actual splitting of store-groups
 	 until after SLP discovery of the original group completed.