The following makes sure that vect_simd_lane_linear does not loop
indefinitely.

Bootstrap/regtest running on x86_64-unknown-linux-gnu.

The testcase invokes UB when update() is called more than
once (the argument isn't linear), but we can't reject it so
we should better not hang building.

OK?

Thanks,
Richard.

        PR tree-optimization/128188
        * tree-vect-stmts.cc (vect_simd_lane_linear): Return when
        the definition v is not handled, avoiding an endless loop.

        * gcc.dg/vect/vect-simd-pr128188.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/vect-simd-pr128188.c | 17 +++++++++++++++++
 gcc/tree-vect-stmts.cc                         |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-simd-pr128188.c

diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-pr128188.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-pr128188.c
new file mode 100644
index 00000000000..b16261efe6f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-pr128188.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fopenmp-simd -fno-tree-loop-im -fno-tree-pre" } */
+
+#pragma omp declare simd linear(p:1) notinbranch
+extern int update(int *p, int x);
+
+void f(int *restrict d, const int *restrict a, int n, int m)
+{
+#pragma omp simd
+  for (int i = 0; i < n; i++)
+    {
+      int t = a[i];
+#pragma omp simd
+      for (int j = 0; j < m; j++)
+       d[i*m+j] = update(&t, a[j]);
+    }
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 462bb709343..e402a745d70 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -4076,8 +4076,8 @@ vect_simd_lane_linear (tree op, class loop *loop,
          arginfo->linear_step = linear_step;
          arginfo->op = base;
          arginfo->simd_lane_linear = true;
-         return;
        }
+      return;
     }
 }
 

base-commit: def63f7c26207e4dfefcf5e92c07ea2582474dc5
-- 
2.51.0

Reply via email to