PR c/59984
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 8 Feb 2014 09:10:14 +0000 (09:10 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 8 Feb 2014 09:10:14 +0000 (09:10 +0000)
* gimplify.c (gimplify_bind_expr): In ORT_SIMD region
mark local addressable non-static vars as GOVD_PRIVATE
instead of GOVD_LOCAL.
* omp-low.c (lower_omp_for): Move gimple_bind_vars
and BLOCK_VARS of gimple_bind_block to new_stmt rather
than copying them.

* gcc.dg/vect/pr59984.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@207629 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gimplify.c
gcc/omp-low.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/pr59984.c [new file with mode: 0644]

index 2b9464a..1c74524 100644 (file)
@@ -1,5 +1,13 @@
 2014-02-08  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/59984
+       * gimplify.c (gimplify_bind_expr): In ORT_SIMD region
+       mark local addressable non-static vars as GOVD_PRIVATE
+       instead of GOVD_LOCAL.
+       * omp-low.c (lower_omp_for): Move gimple_bind_vars
+       and BLOCK_VARS of gimple_bind_block to new_stmt rather
+       than copying them.
+
        PR middle-end/60092
        * tree-ssa-ccp.c (surely_varying_stmt_p): Don't return true
        if TYPE_ATTRIBUTES (gimple_call_fntype ()) contain
index 9c9998d..957a82f 100644 (file)
@@ -1042,7 +1042,14 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
              && (! DECL_SEEN_IN_BIND_EXPR_P (t)
                  || splay_tree_lookup (ctx->variables,
                                        (splay_tree_key) t) == NULL))
-           omp_add_variable (gimplify_omp_ctxp, t, GOVD_LOCAL | GOVD_SEEN);
+           {
+             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);
+           }
 
          DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
 
index 2c35751..f99b2a6 100644 (file)
@@ -8946,8 +8946,14 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   if (!gimple_seq_empty_p (omp_for_body)
       && gimple_code (gimple_seq_first_stmt (omp_for_body)) == GIMPLE_BIND)
     {
-      tree vars = gimple_bind_vars (gimple_seq_first_stmt (omp_for_body));
+      gimple inner_bind = gimple_seq_first_stmt (omp_for_body);
+      tree vars = gimple_bind_vars (inner_bind);
       gimple_bind_append_vars (new_stmt, vars);
+      /* bind_vars/BLOCK_VARS are being moved to new_stmt/block, don't
+        keep them on the inner_bind and it's block.  */
+      gimple_bind_set_vars (inner_bind, NULL_TREE);
+      if (gimple_bind_block (inner_bind))
+       BLOCK_VARS (gimple_bind_block (inner_bind)) = NULL_TREE;
     }
 
   if (gimple_omp_for_combined_into_p (stmt))
index 2740811..053acd0 100644 (file)
@@ -1,5 +1,8 @@
 2014-02-08  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/59984
+       * gcc.dg/vect/pr59984.c: New test.
+
        PR middle-end/60092
        * gcc.dg/attr-alloc_align-1.c: New test.
        * gcc.dg/attr-alloc_align-2.c: New test.
diff --git a/gcc/testsuite/gcc.dg/vect/pr59984.c b/gcc/testsuite/gcc.dg/vect/pr59984.c
new file mode 100644 (file)
index 0000000..c772d82
--- /dev/null
@@ -0,0 +1,64 @@
+/* PR c/59984 */
+/* { dg-additional-options "-fopenmp-simd" } */
+
+#include "tree-vect.h"
+
+#define N 128
+
+int a[N];
+
+#pragma omp declare simd
+__attribute__((noinline)) void
+foo (int in, int *out1, int *out2)
+{
+  *out1 = in * in - 1;
+  *out2 = in * in + 1;
+}
+
+#pragma omp declare simd linear (out1, out2)
+__attribute__((noinline)) void
+bar (int in, int *out1, int *out2)
+{
+  *out1 = in * in - 1;
+  *out2 = in * in + 1;
+}
+
+__attribute__((noinline)) void
+test (void)
+{
+  int i;
+  for (i = 0; i < N; i++)
+    a[i] = i;
+#pragma omp simd
+  for (i = 0; i < N; i++)
+    {
+      int v1, v2;
+      foo (a[i], &v1, &v2);
+      a[i] = v1 * v2;
+    }
+  for (i = 0; i < N; i++)
+    if (a[i] != i * i * i * i - 1)
+      __builtin_abort ();
+  for (i = 0; i < N; i++)
+    a[i] = i;
+#pragma omp simd
+  for (i = 0; i < N; i++)
+    {
+      int v1, v2;
+      bar (a[i], &v1, &v2);
+      a[i] = v1 * v2;
+    }
+  for (i = 0; i < N; i++)
+    if (a[i] != i * i * i * i - 1)
+      __builtin_abort ();
+}
+
+int
+main ()
+{
+  check_vect ();
+  test ();
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */