]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/78884 ([7/8] ICE when gimplifying VLA in OpenMP SIMD region)
authorJakub Jelinek <jakub@redhat.com>
Fri, 30 Aug 2019 12:48:57 +0000 (14:48 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 12:48:57 +0000 (14:48 +0200)
Backported from mainline
2019-07-04  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/78884
* gimplify.c (struct gimplify_omp_ctx): Add add_safelen1 member.
(gimplify_bind_expr): If seeing TREE_ADDRESSABLE VLA inside of simd
loop body, set ctx->add_safelen1 instead of making it GOVD_PRIVATE.
(gimplify_adjust_omp_clauses): Add safelen (1) clause if
ctx->add_safelen1 is set.

* gcc.dg/gomp/pr78884.c: New test.

From-SVN: r275163

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/gomp/pr78884.c [new file with mode: 0644]

index 8de4dd60beec06d69f520f65d163121185ed0ddd..2fa1b755c688a0f459536984f8082b71f1e47ac8 100644 (file)
@@ -3,6 +3,13 @@
        Backported from mainline
        2019-07-04  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/78884
+       * gimplify.c (struct gimplify_omp_ctx): Add add_safelen1 member.
+       (gimplify_bind_expr): If seeing TREE_ADDRESSABLE VLA inside of simd
+       loop body, set ctx->add_safelen1 instead of making it GOVD_PRIVATE.
+       (gimplify_adjust_omp_clauses): Add safelen (1) clause if
+       ctx->add_safelen1 is set.
+
        PR rtl-optimization/90756
        * explow.c (promote_ssa_mode): Always use TYPE_MODE, don't bypass it
        for VECTOR_TYPE_P.
index 0e92ffe4ea2cbb31a3b9d9a388b8f1dda179da66..84e541c039fb0d71196d7df0bc064a197bf05114 100644 (file)
@@ -185,6 +185,7 @@ struct gimplify_omp_ctx
   bool target_map_scalars_firstprivate;
   bool target_map_pointers_as_0len_arrays;
   bool target_firstprivatize_array_bases;
+  bool add_safelen1;
 };
 
 static struct gimplify_ctx *gimplify_ctxp;
@@ -1251,12 +1252,17 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
                  || splay_tree_lookup (ctx->variables,
                                        (splay_tree_key) t) == NULL))
            {
+             int flag = GOVD_LOCAL;
              if (ctx->region_type == ORT_SIMD
                  && TREE_ADDRESSABLE (t)
                  && !TREE_STATIC (t))
-               omp_add_variable (ctx, t, GOVD_PRIVATE | GOVD_SEEN);
-             else
-               omp_add_variable (ctx, t, GOVD_LOCAL | GOVD_SEEN);
+               {
+                 if (TREE_CODE (DECL_SIZE_UNIT (t)) != INTEGER_CST)
+                   ctx->add_safelen1 = true;
+                 else
+                   flag = GOVD_PRIVATE;
+               }
+             omp_add_variable (ctx, t, flag | GOVD_SEEN);
            }
 
          DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
@@ -8811,6 +8817,19 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p,
                           omp_find_stores_op, &wi);
        }
     }
+
+  if (ctx->add_safelen1)
+    {
+      /* If there are VLAs in the body of simd loop, prevent
+        vectorization.  */
+      gcc_assert (ctx->region_type == ORT_SIMD);
+      c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SAFELEN);
+      OMP_CLAUSE_SAFELEN_EXPR (c) = integer_one_node;
+      OMP_CLAUSE_CHAIN (c) = *list_p;
+      *list_p = c;
+      list_p = &OMP_CLAUSE_CHAIN (c);
+    }
+
   while ((c = *list_p) != NULL)
     {
       splay_tree_node n;
index 48caf134dea48f77c6bedf3dbc07673aafdb340f..048960ab12243cf6ca7a74773fe73b5ef867c35d 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2019-07-04  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/78884
+       * gcc.dg/gomp/pr78884.c: New test.
+
        PR rtl-optimization/90756
        * gcc.dg/pr90756.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/gomp/pr78884.c b/gcc/testsuite/gcc.dg/gomp/pr78884.c
new file mode 100644 (file)
index 0000000..3e03df5
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR middle-end/78884 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp" } */
+
+void bar (int *);
+
+void
+foo (int n)
+{
+#pragma omp simd
+  for (int i = 0; i < 1024; i++)
+    {
+      int vla[n];
+      bar (vla);
+    }
+}