[1/2] Use the number of relevant stmts to limit SLP build

Message ID 20241203112607.3758813A15@imap1.dmz-prg2.suse.org
State Committed
Commit d4f3c3efc669afe6e270344ff73c7471fea67ce7
Headers
Series [1/2] Use the number of relevant stmts to limit SLP build |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Richard Biener Dec. 3, 2024, 11:26 a.m. UTC
  The following removes scalar stmt counting from loop vectorization
and using that as base to limit both the SLP tree final size and
discovery.  Instead use the number of relevant stmts for that
which is conveniently the number of stmt_vec_infos we create which
in turn includes things like pattern stmts.

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

	PR tree-optimization/117874
	* tree-vectorizer.h (vec_info_shared::n_stmts): Remove.
	(LOOP_VINFO_N_STMTS): Likewise.
	* tree-vectorizer.cc (vec_info_shared::vec_info_shared): Adjust.
	* tree-vect-loop.cc (vect_get_datarefs_in_loop): Do not
	count stmts.
	(vect_analyze_loop_2): Adjust.  Pass stmt_vec_info.length ()
	to vect_analyze_slp as SLP tree size limit.
---
 gcc/tree-vect-loop.cc  | 10 +++-------
 gcc/tree-vectorizer.cc |  3 +--
 gcc/tree-vectorizer.h  |  4 ----
 3 files changed, 4 insertions(+), 13 deletions(-)
  

Patch

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 85209604486..4f401cd2d0c 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -2499,10 +2499,8 @@  vect_analyze_loop_costing (loop_vec_info loop_vinfo,
 
 static opt_result
 vect_get_datarefs_in_loop (loop_p loop, basic_block *bbs,
-			   vec<data_reference_p> *datarefs,
-			   unsigned int *n_stmts)
+			   vec<data_reference_p> *datarefs)
 {
-  *n_stmts = 0;
   for (unsigned i = 0; i < loop->num_nodes; i++)
     for (gimple_stmt_iterator gsi = gsi_start_bb (bbs[i]);
 	 !gsi_end_p (gsi); gsi_next (&gsi))
@@ -2510,7 +2508,6 @@  vect_get_datarefs_in_loop (loop_p loop, basic_block *bbs,
 	gimple *stmt = gsi_stmt (gsi);
 	if (is_gimple_debug (stmt))
 	  continue;
-	++(*n_stmts);
 	opt_result res = vect_find_stmt_data_reference (loop, stmt, datarefs,
 							NULL, 0);
 	if (!res)
@@ -2786,8 +2783,7 @@  vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal,
     {
       opt_result res
 	= vect_get_datarefs_in_loop (loop, LOOP_VINFO_BBS (loop_vinfo),
-				     &LOOP_VINFO_DATAREFS (loop_vinfo),
-				     &LOOP_VINFO_N_STMTS (loop_vinfo));
+				     &LOOP_VINFO_DATAREFS (loop_vinfo));
       if (!res)
 	{
 	  if (dump_enabled_p ())
@@ -2898,7 +2894,7 @@  start_over:
     {
       /* Check the SLP opportunities in the loop, analyze and build
 	 SLP trees.  */
-      ok = vect_analyze_slp (loop_vinfo, LOOP_VINFO_N_STMTS (loop_vinfo),
+      ok = vect_analyze_slp (loop_vinfo, loop_vinfo->stmt_vec_infos.length (),
 			     slp == 1);
       if (!ok)
 	return ok;
diff --git a/gcc/tree-vectorizer.cc b/gcc/tree-vectorizer.cc
index 9a068a40864..0bec28048f4 100644
--- a/gcc/tree-vectorizer.cc
+++ b/gcc/tree-vectorizer.cc
@@ -480,8 +480,7 @@  vec_info::~vec_info ()
 }
 
 vec_info_shared::vec_info_shared ()
-  : n_stmts (0),
-    datarefs (vNULL),
+  : datarefs (vNULL),
     datarefs_copy (vNULL),
     ddrs (vNULL)
 {
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 7f69a3f57b4..1059fc5c18f 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -474,9 +474,6 @@  public:
   void save_datarefs();
   void check_datarefs();
 
-  /* The number of scalar stmts.  */
-  unsigned n_stmts;
-
   /* All data references.  Freed by free_data_refs, so not an auto_vec.  */
   vec<data_reference_p> datarefs;
   vec<data_reference> datarefs_copy;
@@ -1070,7 +1067,6 @@  public:
 #define LOOP_VINFO_RGROUP_IV_TYPE(L)       (L)->rgroup_iv_type
 #define LOOP_VINFO_PARTIAL_VECTORS_STYLE(L) (L)->partial_vector_style
 #define LOOP_VINFO_PTR_MASK(L)             (L)->ptr_mask
-#define LOOP_VINFO_N_STMTS(L)		   (L)->shared->n_stmts
 #define LOOP_VINFO_LOOP_NEST(L)            (L)->shared->loop_nest
 #define LOOP_VINFO_DATAREFS(L)             (L)->shared->datarefs
 #define LOOP_VINFO_DDRS(L)                 (L)->shared->ddrs