]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/116083 - SLP discovery slowness
authorRichard Biener <rguenther@suse.de>
Tue, 3 Dec 2024 13:37:21 +0000 (14:37 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 4 Dec 2024 09:12:29 +0000 (10:12 +0100)
One large constant factor of SLP discovery is figuring the vector
type for each individual lane of each node.  That should be redundant
since the structual comparison of stmts should ensure they end up
the same so the following computes them only once per node rather
than for each lane.

This cuts the compile-time of the testcase in half.

PR tree-optimization/116083
* tree-vect-slp.cc (vect_build_slp_tree_1): Compute vector
type and max_nunits only once.  Remove check for matching
vector type of each lane and replace it with matching check
for LHS type.

gcc/tree-vect-slp.cc

index 425135a9ee0afd409c6c371fe4faab9c9723beba..9ad95104ec7da2cc3861e1395e8f3fb8d4b62796 100644 (file)
@@ -1092,8 +1092,8 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
   code_helper first_stmt_code = ERROR_MARK;
   code_helper alt_stmt_code = ERROR_MARK;
   code_helper first_cond_code = ERROR_MARK;
-  tree lhs;
   bool need_same_oprnds = false;
+  tree first_lhs = NULL_TREE;
   tree first_op1 = NULL_TREE;
   stmt_vec_info first_load = NULL, prev_first_load = NULL;
   bool first_stmt_ldst_p = false;
@@ -1102,6 +1102,29 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
   bool maybe_soft_fail = false;
   tree soft_fail_nunits_vectype = NULL_TREE;
 
+  tree vectype, nunits_vectype;
+  if (!vect_get_vector_types_for_stmt (vinfo, first_stmt_info, &vectype,
+                                      &nunits_vectype, group_size))
+    {
+      /* Fatal mismatch.  */
+      matches[0] = false;
+      return false;
+    }
+  /* Record nunits required but continue analysis, producing matches[]
+     as if nunits was not an issue.  This allows splitting of groups
+     to happen.  */
+  if (nunits_vectype
+      && !vect_record_max_nunits (vinfo, first_stmt_info, group_size,
+                                 nunits_vectype, max_nunits))
+    {
+      gcc_assert (is_a <bb_vec_info> (vinfo));
+      maybe_soft_fail = true;
+      soft_fail_nunits_vectype = nunits_vectype;
+    }
+
+  gcc_assert (vectype);
+  *node_vectype = vectype;
+
   /* For every stmt in NODE find its def stmt/s.  */
   stmt_vec_info stmt_info;
   FOR_EACH_VEC_ELT (stmts, i, stmt_info)
@@ -1144,7 +1167,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
         }
 
       gcall *call_stmt = dyn_cast <gcall *> (stmt);
-      lhs = gimple_get_lhs (stmt);
+      tree lhs = gimple_get_lhs (stmt);
       if (lhs == NULL_TREE
          && (!call_stmt
              || !gimple_call_internal_p (stmt)
@@ -1161,30 +1184,6 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
          return false;
        }
 
-      tree vectype, nunits_vectype;
-      if (!vect_get_vector_types_for_stmt (vinfo, stmt_info, &vectype,
-                                          &nunits_vectype, group_size))
-       {
-         if (is_a <bb_vec_info> (vinfo) && i != 0)
-           continue;
-         /* Fatal mismatch.  */
-         matches[0] = false;
-         return false;
-       }
-      /* Record nunits required but continue analysis, producing matches[]
-        as if nunits was not an issue.  This allows splitting of groups
-        to happen.  */
-      if (nunits_vectype
-         && !vect_record_max_nunits (vinfo, stmt_info, group_size,
-                                     nunits_vectype, max_nunits))
-       {
-         gcc_assert (is_a <bb_vec_info> (vinfo));
-         maybe_soft_fail = true;
-         soft_fail_nunits_vectype = nunits_vectype;
-       }
-
-      gcc_assert (vectype);
-
       if (call_stmt)
        {
          combined_fn cfn = gimple_call_combined_fn (call_stmt);
@@ -1241,7 +1240,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
       /* Check the operation.  */
       if (i == 0)
        {
-         *node_vectype = vectype;
+         first_lhs = lhs;
          first_stmt_code = rhs_code;
          first_stmt_ldst_p = ldst_p;
          first_stmt_phi_p = phi_p;
@@ -1432,7 +1431,9 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
                }
            }
 
-         if (!types_compatible_p (vectype, *node_vectype))
+         if (first_lhs
+             && lhs
+             && !types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (first_lhs)))
            {
              if (dump_enabled_p ())
                dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,