diff mbox series

RISC-V: Handle NULL stmt in SLP_TREE_SCALAR_STMTS

Message ID 20240628141113.5635C13375@imap1.dmz-prg2.suse.org
State New
Headers show
Series RISC-V: Handle NULL stmt in SLP_TREE_SCALAR_STMTS | expand

Commit Message

Richard Biener June 28, 2024, 2:11 p.m. UTC
The following starts to handle NULL elements in SLP_TREE_SCALAR_STMTS
with the first candidate being the two-operator nodes where some
lanes are do-not-care and also do not have a scalar stmt computing
the result.  I've sofar whack-a-moled the vect.exp testsuite.

I do plan to use NULL elements for loads from groups with gaps
where we get around not doing that by having a load permutation.

I want to separate changing places where I have coverage from those
I do not.  So this is for the CI and I'll followup with patching up
all remaining iterations over SLP_TREE_SCALAR_STMTS.

	* tree-vect-slp.cc (vect_build_slp_tree_2): Make two-operator
	nodes have SLP_TREE_SCALAR_STMTS with do-not-care lanes NULL.
	(bst_traits::hash): Handle NULL elements in SLP_TREE_SCALAR_STMTS.
	(vect_print_slp_tree): Likewise.
	(vect_mark_slp_stmts): Likewise.
	(vect_mark_slp_stmts_relevant): Likewise.
	(vect_find_last_scalar_stmt_in_slp): Likewise.
	(vect_bb_slp_mark_live_stmts): Likewise.
	(vect_slp_prune_covered_roots): Likewise.
	(vect_bb_partition_graph_r): Likewise.
	(vect_remove_slp_scalar_calls): Likewise.
	* tree-vect-stmts.cc (can_vectorize_live_stmts): Likewise.
---
 gcc/tree-vect-slp.cc   | 56 ++++++++++++++++++++++++++++--------------
 gcc/tree-vect-stmts.cc | 11 +++++----
 2 files changed, 43 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index dd9017e5b3a..47664158e57 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -1571,7 +1571,7 @@  bst_traits::hash (value_type x)
 {
   inchash::hash h;
   for (unsigned i = 0; i < x.length (); ++i)
-    h.add_int (gimple_uid (x[i]->stmt));
+    h.add_int (x[i] ? gimple_uid (x[i]->stmt) : -1);
   return h.end ();
 }
 inline bool
@@ -2702,6 +2702,8 @@  fail:
       SLP_TREE_VECTYPE (two) = vectype;
       SLP_TREE_CHILDREN (one).safe_splice (children);
       SLP_TREE_CHILDREN (two).safe_splice (children);
+      SLP_TREE_SCALAR_STMTS (one).create (stmts.length ());
+      SLP_TREE_SCALAR_STMTS (two).create (stmts.length ());
       slp_tree child;
       FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (two), i, child)
 	SLP_TREE_REF_COUNT (child)++;
@@ -2726,9 +2728,15 @@  fail:
 	      SLP_TREE_LANE_PERMUTATION (node).safe_push (std::make_pair (1, i));
 	      ocode = gimple_assign_rhs_code (ostmt);
 	      j = i;
+	      SLP_TREE_SCALAR_STMTS (one).quick_push (NULL);
+	      SLP_TREE_SCALAR_STMTS (two).quick_push (stmts[i]);
 	    }
 	  else
-	    SLP_TREE_LANE_PERMUTATION (node).safe_push (std::make_pair (0, i));
+	    {
+	      SLP_TREE_LANE_PERMUTATION (node).safe_push (std::make_pair (0, i));
+	      SLP_TREE_SCALAR_STMTS (one).quick_push (stmts[i]);
+	      SLP_TREE_SCALAR_STMTS (two).quick_push (NULL);
+	    }
 	}
       SLP_TREE_CODE (one) = code0;
       SLP_TREE_CODE (two) = ocode;
@@ -2781,9 +2789,12 @@  vect_print_slp_tree (dump_flags_t dump_kind, dump_location_t loc,
     }
   if (SLP_TREE_SCALAR_STMTS (node).exists ())
     FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
-      dump_printf_loc (metadata, user_loc, "\t%sstmt %u %G",
-		       STMT_VINFO_LIVE_P (stmt_info) ? "[l] " : "",
-		       i, stmt_info->stmt);
+      if (stmt_info)
+	dump_printf_loc (metadata, user_loc, "\t%sstmt %u %G",
+			 STMT_VINFO_LIVE_P (stmt_info) ? "[l] " : "",
+			 i, stmt_info->stmt);
+      else
+	dump_printf_loc (metadata, user_loc, "\tstmt %u ---\n");
   else
     {
       dump_printf_loc (metadata, user_loc, "\t{ ");
@@ -2924,7 +2935,8 @@  vect_mark_slp_stmts (slp_tree node, hash_set<slp_tree> &visited)
     return;
 
   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
-    STMT_SLP_TYPE (stmt_info) = pure_slp;
+    if (stmt_info)
+      STMT_SLP_TYPE (stmt_info) = pure_slp;
 
   FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
     if (child)
@@ -2954,11 +2966,12 @@  vect_mark_slp_stmts_relevant (slp_tree node, hash_set<slp_tree> &visited)
     return;
 
   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
-    {
-      gcc_assert (!STMT_VINFO_RELEVANT (stmt_info)
-                  || STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_scope);
-      STMT_VINFO_RELEVANT (stmt_info) = vect_used_in_scope;
-    }
+    if (stmt_info)
+      {
+	gcc_assert (!STMT_VINFO_RELEVANT (stmt_info)
+		    || STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_scope);
+	STMT_VINFO_RELEVANT (stmt_info) = vect_used_in_scope;
+      }
 
   FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
     if (child)
@@ -3009,10 +3022,11 @@  vect_find_last_scalar_stmt_in_slp (slp_tree node)
   stmt_vec_info stmt_vinfo;
 
   for (int i = 0; SLP_TREE_SCALAR_STMTS (node).iterate (i, &stmt_vinfo); i++)
-    {
-      stmt_vinfo = vect_orig_stmt (stmt_vinfo);
-      last = last ? get_later_stmt (stmt_vinfo, last) : stmt_vinfo;
-    }
+    if (stmt_vinfo)
+      {
+	stmt_vinfo = vect_orig_stmt (stmt_vinfo);
+	last = last ? get_later_stmt (stmt_vinfo, last) : stmt_vinfo;
+      }
 
   return last;
 }
@@ -6895,7 +6909,7 @@  vect_bb_slp_mark_live_stmts (bb_vec_info bb_vinfo, slp_tree node,
   stmt_vec_info last_stmt = vect_find_last_scalar_stmt_in_slp (node);
   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
     {
-      if (svisited.contains (stmt_info))
+      if (!stmt_info || svisited.contains (stmt_info))
 	continue;
       stmt_vec_info orig_stmt_info = vect_orig_stmt (stmt_info);
       if (STMT_VINFO_IN_PATTERN_P (orig_stmt_info)
@@ -7084,7 +7098,8 @@  vect_slp_prune_covered_roots (slp_tree node, hash_set<stmt_vec_info> &roots,
   stmt_vec_info stmt;
   unsigned i;
   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt)
-    roots.remove (vect_orig_stmt (stmt));
+    if (stmt)
+      roots.remove (vect_orig_stmt (stmt));
 
   slp_tree child;
   FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
@@ -7260,8 +7275,9 @@  vect_bb_partition_graph_r (bb_vec_info bb_vinfo,
   unsigned i;
 
   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
-    vect_map_to_instance (instance, stmt_info, stmt_to_instance,
-			  instance_leader);
+    if (stmt_info)
+      vect_map_to_instance (instance, stmt_info, stmt_to_instance,
+			    instance_leader);
 
   if (vect_map_to_instance (instance, node, node_to_instance,
 			    instance_leader))
@@ -9824,6 +9840,8 @@  vect_remove_slp_scalar_calls (vec_info *vinfo,
 
   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
     {
+      if (!stmt_info)
+	continue;
       gcall *stmt = dyn_cast <gcall *> (stmt_info->stmt);
       if (!stmt || gimple_bb (stmt) == NULL)
 	continue;
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 7b889f31645..ec73b47b845 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -13081,11 +13081,12 @@  can_vectorize_live_stmts (vec_info *vinfo, stmt_vec_info stmt_info,
       unsigned int i;
       FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (slp_node), i, slp_stmt_info)
 	{
-	  if ((STMT_VINFO_LIVE_P (slp_stmt_info)
-	       || (loop_vinfo
-		   && LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
-		   && STMT_VINFO_DEF_TYPE (slp_stmt_info)
-			== vect_induction_def))
+	  if (slp_stmt_info
+	      && (STMT_VINFO_LIVE_P (slp_stmt_info)
+		  || (loop_vinfo
+		      && LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
+		      && STMT_VINFO_DEF_TYPE (slp_stmt_info)
+		      == vect_induction_def))
 	      && !vectorizable_live_operation (vinfo, slp_stmt_info, slp_node,
 					       slp_node_instance, i,
 					       vec_stmt_p, cost_vec))