When we cannot compute a vector type for an uniform arg of a SIMD
function we'll ICE, latest when assigning the vector type to the
SLP node if it is invariant.  Give up for such uniform args.
If passing the scalar argument would be OK we should refrain from
tracking it in a SLP node (or generally enhance that to handle
"scalar lanes").

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

        PR tree-optimization/128189
        * tree-vect-stmts.cc (vectorizable_simd_clone_call): When
        the vector type of an argument cannot be computed, fail.

        * gcc.dg/vect/vect-simd-pr128189.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/vect-simd-pr128189.c | 15 +++++++++++++++
 gcc/tree-vect-stmts.cc                         | 18 +++++++++++++++---
 2 files changed, 30 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-simd-pr128189.c

diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-pr128189.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-pr128189.c
new file mode 100644
index 00000000000..472e1db1355
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-pr128189.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fopenmp-simd" } */
+
+#pragma omp declare simd uniform(x) simdlen(4) notinbranch
+extern void f(_Complex double x);
+
+void g(int *restrict d, _Complex double x, int n)
+{
+#pragma omp simd
+  for (int i = 0; i < n; i++)
+    {
+      f(x);
+      d[i] = 1;
+    }
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 0a884d491e3..b33d3f6b782 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -4176,9 +4176,21 @@ vectorizable_simd_clone_call (vec_info *vinfo, 
stmt_vec_info stmt_info,
          gcc_assert (cost_vec
                      || thisarginfo.vectype != NULL_TREE);
          if (cost_vec)
-           thisarginfo.vectype = get_vectype_for_scalar_type (vinfo,
-                                                              TREE_TYPE (op),
-                                                              slp_node);
+           {
+             thisarginfo.vectype = get_vectype_for_scalar_type (vinfo,
+                                                                TREE_TYPE (op),
+                                                                slp_node);
+             /* ???  While for example uniform arguments might not need
+                a vector type we are not set up to handle this case
+                right now.  */
+             if (!thisarginfo.vectype)
+               {
+                 if (dump_enabled_p ())
+                   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                                    "no vector type for argument.\n");
+                 return false;
+               }
+           }
        }
       else
        gcc_assert (thisarginfo.vectype != NULL_TREE);

base-commit: c06252ee5215bfb58ad97a8636234fc67318e052
-- 
2.51.0

Reply via email to