]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
omp-low.c (lower_omp_task_reductions): For array section reductions...
authorJakub Jelinek <jakub@redhat.com>
Mon, 8 Oct 2018 15:40:13 +0000 (17:40 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 8 Oct 2018 15:40:13 +0000 (17:40 +0200)
* omp-low.c (lower_omp_task_reductions): For array section reductions,
read address from avar array instead of computing it again at the end
of taskgroup, as the base might have changed during the taskgroup.

* testsuite/libgomp.c-c++-common/task-reduction-5.c: New test.

From-SVN: r264938

gcc/ChangeLog.gomp
gcc/omp-low.c
libgomp/ChangeLog.gomp
libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c [new file with mode: 0644]

index 41dcbcfcef90ae5b2042e61ee80045f819e296ba..854da5e4647d5fc4d2e45be1bb437c2340b84a98 100644 (file)
@@ -1,3 +1,9 @@
+2018-10-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * omp-low.c (lower_omp_task_reductions): For array section reductions,
+       read address from avar array instead of computing it again at the end
+       of taskgroup, as the base might have changed during the taskgroup.
+
 2018-09-27  Jakub Jelinek  <jakub@redhat.com>
 
        * omp-low.c (lower_rec_input_clauses): Fix handling of
index adb65c841b3f88456a14d1c2fce9cb35e1bce84f..8acffdb9bc2930597b74493a8a4c9de58eb614f6 100644 (file)
@@ -6787,7 +6787,7 @@ lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses,
           omp_task_reduction_iterate (pass, code, ccode,
                                       &c, &decl, &type, &next); c = next)
        {
-         tree var = decl, ref, orig_var = decl;
+         tree var = decl, ref;
          if (TREE_CODE (decl) == MEM_REF)
            {
              var = TREE_OPERAND (var, 0);
@@ -6798,7 +6798,6 @@ lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses,
                var = TREE_OPERAND (var, 0);
              else if (TREE_CODE (var) == INDIRECT_REF)
                var = TREE_OPERAND (var, 0);
-             orig_var = var;
              if (is_variable_sized (var))
                {
                  gcc_assert (DECL_HAS_VALUE_EXPR_P (var));
@@ -6895,48 +6894,17 @@ lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses,
            rcode = PLUS_EXPR;
          if (TREE_CODE (decl) == MEM_REF)
            {
-             tree d = decl;
              tree type = TREE_TYPE (new_var);
              tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
              tree i = create_tmp_var (TREE_TYPE (v), NULL);
              tree ptype = build_pointer_type (TREE_TYPE (type));
-             tree bias = TREE_OPERAND (d, 1);
-             d = TREE_OPERAND (d, 0);
-             if (TREE_CODE (d) == POINTER_PLUS_EXPR)
-               {
-                 tree b = TREE_OPERAND (d, 1);
-                 b = maybe_lookup_decl_in_outer_ctx (b, ctx);
-                 if (integer_zerop (bias))
-                   bias = b;
-                 else
-                   {
-                     bias = fold_convert (TREE_TYPE (b), bias);
-                     bias = fold_build2 (PLUS_EXPR, TREE_TYPE (b), b, bias);
-                   }
-                 d = TREE_OPERAND (d, 0);
-               }
-             /* For ref build_outer_var_ref already performs this, so
-                only new_var needs a dereference.  */
-             if (TREE_CODE (d) == INDIRECT_REF)
-               ref = build_fold_indirect_ref (ref);
-             else if (TREE_CODE (d) == ADDR_EXPR)
-               {
-                 if (orig_var == var)
-                   ref = build_fold_addr_expr (ref);
-               }
-             else
-               gcc_assert (orig_var == var);
              if (DECL_P (v))
                {
                  v = maybe_lookup_decl_in_outer_ctx (v, ctx);
                  gimplify_expr (&v, end, NULL, is_gimple_val, fb_rvalue);
                }
-             if (!integer_zerop (bias))
-               {
-                 bias = fold_convert (sizetype, bias);
-                 ref = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (ref),
-                                    ref, bias);
-               }
+             ref = build4 (ARRAY_REF, pointer_sized_int_node, avar,
+                           size_int (7 + cnt * 3), NULL_TREE, NULL_TREE);
              new_var = build_fold_addr_expr (new_var);
              new_var = fold_convert (ptype, new_var);
              ref = fold_convert (ptype, ref);
index cadbcb05c247436608df1977809e8c09ac33ace8..6e8b30c779d90b9fa03bf7ce00d23312645b6c84 100644 (file)
@@ -1,5 +1,7 @@
 2018-10-08  Jakub Jelinek  <jakub@redhat.com>
 
+       * testsuite/libgomp.c-c++-common/task-reduction-5.c: New test.
+
        * env.c (gomp_affinity_format_var): Use %i instead of %T and
        %A instead of %a.
        * affinity-fmt.c (affinity_types): Change short forms h to H,
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c
new file mode 100644 (file)
index 0000000..52880ec
--- /dev/null
@@ -0,0 +1,55 @@
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+
+int *q;
+
+void
+bar (int *p, int *r, int s)
+{
+  #pragma omp task in_reduction (*: p[0], q[0], r[s - 1])
+  {
+    *p *= 4;
+    *q *= 5;
+    r[s - 1] *= 6;
+  }
+}
+
+void
+foo (int *p, int *r, int s)
+{
+  int *p2 = p;
+  #pragma omp taskgroup task_reduction (*: p[0], q[0], r[s])
+  {
+    p = (int *) 0;
+    s++;
+    bar (p2, r, s);
+    r++;
+    #pragma omp taskwait
+    #pragma omp task in_reduction (*: p2[0], q[0], r[s - 2])
+    {
+      *p2 *= 2;
+      *q *= 3;
+      r[s - 2] *= 7;
+    }
+    s++;
+    p2 = (int *) 0;
+    q = (int *) 0;
+    r = (int *) 0;
+  }
+}
+
+int
+main ()
+{
+  int a = 1, b = 1, c[2] = { 1, 0 };
+  q = &b;
+  #pragma omp parallel num_threads (2)
+  #pragma omp master
+  foo (&a, &c[0], 0);
+  if (a != 8 || b != 15 || c[0] != 42 || c[1] != 0)
+    abort ();
+  return 0;
+}