diff mbox series

tree-optimization/99721 - avoid SLP nodes we cannot schedule

Message ID nycvar.YFH.7.76.2103231049390.19165@elmra.sevgm.obk
State New
Headers show
Series tree-optimization/99721 - avoid SLP nodes we cannot schedule | expand

Commit Message

Richard Biener March 23, 2021, 9:49 a.m. UTC
This makes sure we'll not run into SLP scheduling issues later by
rejecting all-constant children nodes without any scalar stmts early.

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

2021-03-23  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/99721
	* tree-vect-slp.c (vect_slp_analyze_node_operations):
	Make sure we can schedule the node.

	* gfortran.dg/vect/pr99721.f90: New testcase.
---
 gcc/testsuite/gfortran.dg/vect/pr99721.f90 | 11 +++++++++++
 gcc/tree-vect-slp.c                        | 15 ++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/vect/pr99721.f90
diff mbox series

Patch

diff --git a/gcc/testsuite/gfortran.dg/vect/pr99721.f90 b/gcc/testsuite/gfortran.dg/vect/pr99721.f90
new file mode 100644
index 00000000000..651e86ac3f8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/vect/pr99721.f90
@@ -0,0 +1,11 @@ 
+! { dg-do compile }
+! { dg-additional-options "-O3" }
+! { dg-additional-options "-march=armv8.3-a" { target aarch64-*-* } }
+subroutine sub_c
+  complex, dimension(2,3) :: at
+  complex, dimension(2,4) :: b
+  complex, dimension(3,4) :: c
+  data b / (41., 43.), 0, 0, 0, 0, 0, 0, 0/
+  c = matmul(transpose(at), b)
+  if (any (c /= cres)) stop
+end subroutine sub_c
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 0d24be796e8..f1a2b5d60fa 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -3893,7 +3893,7 @@  vect_slp_analyze_node_operations (vec_info *vinfo, slp_tree node,
     {
       if (dump_enabled_p ())
 	dump_printf_loc (MSG_NOTE, vect_location,
-			 "Failed cyclic SLP reference in %p", node);
+			 "Failed cyclic SLP reference in %p\n", node);
       return false;
     }
   gcc_assert (SLP_TREE_DEF_TYPE (node) == vect_internal_def);
@@ -3907,6 +3907,7 @@  vect_slp_analyze_node_operations (vec_info *vinfo, slp_tree node,
   bool res = true;
   unsigned visited_rec_start = visited_vec.length ();
   unsigned cost_vec_rec_start = cost_vec->length ();
+  bool seen_non_constant_child = false;
   FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
     {
       res = vect_slp_analyze_node_operations (vinfo, child, node_instance,
@@ -3914,6 +3915,18 @@  vect_slp_analyze_node_operations (vec_info *vinfo, slp_tree node,
 					      cost_vec);
       if (!res)
 	break;
+      if (child && SLP_TREE_DEF_TYPE (child) != vect_constant_def)
+	seen_non_constant_child = true;
+    }
+  /* We're having difficulties scheduling nodes with just constant
+     operands and no scalar stmts since we then cannot compute a stmt
+     insertion place.  */
+  if (!seen_non_constant_child && SLP_TREE_SCALAR_STMTS (node).is_empty ())
+    {
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_NOTE, vect_location,
+			 "Cannot vectorize all-constant op node %p\n", node);
+      res = false;
     }
 
   if (res)