public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10657] openmp: Fix up handling of reduction clauses on the loop construct [PR102431]
@ 2022-05-10 8:21 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-05-10 8:21 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:18e0162ecb5de800f1609bfda657183bf95c7901
commit r10-10657-g18e0162ecb5de800f1609bfda657183bf95c7901
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Nov 23 10:30:02 2021 +0100
openmp: Fix up handling of reduction clauses on the loop construct [PR102431]
We were using unshare_expr and walk_tree_without_duplicate replacement
of the placeholder vars. The OMP_CLAUSE_REDUCTION_{INIT,MERGE} can contain
other trees that need to be duplicated though, e.g. BLOCKs referenced in
BIND_EXPR(s), or local VAR_DECLs. This patch uses the inliner code to copy
all of that. There is a slight complication that those local VAR_DECLs or
placeholders don't have DECL_CONTEXT set, they will get that only when
they are gimplified later on, so this patch sets DECL_CONTEXT for those
temporarily and resets it afterwards.
2021-11-23 Jakub Jelinek <jakub@redhat.com>
PR middle-end/102431
* gimplify.c (replace_reduction_placeholders): Remove.
(note_no_context_vars): New function.
(gimplify_omp_loop): For OMP_PARALLEL's BIND_EXPR create a new
BLOCK. Use copy_tree_body_r with walk_tree instead of unshare_expr
and replace_reduction_placeholders for duplication of
OMP_CLAUSE_REDUCTION_{INIT,MERGE} expressions. Ensure all mentioned
automatic vars have DECL_CONTEXT set to non-NULL before doing so
and reset it afterwards for those vars and their corresponding
vars.
* c-c++-common/gomp/pr102431.c: New test.
* g++.dg/gomp/pr102431.C: New test.
(cherry picked from commit 5e9b973bd60185f221222022f56db7df3d92250e)
Diff:
---
gcc/gimplify.c | 88 +++++++++++++++++++++---------
gcc/testsuite/c-c++-common/gomp/pr102431.c | 16 ++++++
gcc/testsuite/g++.dg/gomp/pr102431.C | 13 +++++
3 files changed, 91 insertions(+), 26 deletions(-)
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index ff81ede350d..d324406193f 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -12255,21 +12255,15 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
/* Helper for gimplify_omp_loop, called through walk_tree. */
static tree
-replace_reduction_placeholders (tree *tp, int *walk_subtrees, void *data)
+note_no_context_vars (tree *tp, int *, void *data)
{
- if (DECL_P (*tp))
+ if (VAR_P (*tp)
+ && DECL_CONTEXT (*tp) == NULL_TREE
+ && !is_global_var (*tp))
{
- tree *d = (tree *) data;
- if (*tp == OMP_CLAUSE_REDUCTION_PLACEHOLDER (d[0]))
- {
- *tp = OMP_CLAUSE_REDUCTION_PLACEHOLDER (d[1]);
- *walk_subtrees = 0;
- }
- else if (*tp == OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (d[0]))
- {
- *tp = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (d[1]);
- *walk_subtrees = 0;
- }
+ vec<tree> *d = (vec<tree> *) data;
+ d->safe_push (*tp);
+ DECL_CONTEXT (*tp) = current_function_decl;
}
return NULL_TREE;
}
@@ -12438,7 +12432,8 @@ gimplify_omp_loop (tree *expr_p, gimple_seq *pre_p)
{
if (pass == 2)
{
- tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
+ tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL,
+ make_node (BLOCK));
append_to_statement_list (*expr_p, &BIND_EXPR_BODY (bind));
*expr_p = make_node (OMP_PARALLEL);
TREE_TYPE (*expr_p) = void_type_node;
@@ -12505,25 +12500,66 @@ gimplify_omp_loop (tree *expr_p, gimple_seq *pre_p)
*pc = copy_node (c);
OMP_CLAUSE_DECL (*pc) = unshare_expr (OMP_CLAUSE_DECL (c));
TREE_TYPE (*pc) = unshare_expr (TREE_TYPE (c));
- OMP_CLAUSE_REDUCTION_INIT (*pc)
- = unshare_expr (OMP_CLAUSE_REDUCTION_INIT (c));
- OMP_CLAUSE_REDUCTION_MERGE (*pc)
- = unshare_expr (OMP_CLAUSE_REDUCTION_MERGE (c));
if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (*pc))
{
+ auto_vec<tree> no_context_vars;
+ int walk_subtrees = 0;
+ note_no_context_vars (&OMP_CLAUSE_REDUCTION_PLACEHOLDER (c),
+ &walk_subtrees, &no_context_vars);
+ if (tree p = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c))
+ note_no_context_vars (&p, &walk_subtrees, &no_context_vars);
+ walk_tree_without_duplicates (&OMP_CLAUSE_REDUCTION_INIT (c),
+ note_no_context_vars,
+ &no_context_vars);
+ walk_tree_without_duplicates (&OMP_CLAUSE_REDUCTION_MERGE (c),
+ note_no_context_vars,
+ &no_context_vars);
+
OMP_CLAUSE_REDUCTION_PLACEHOLDER (*pc)
= copy_node (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c));
if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (*pc))
OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (*pc)
= copy_node (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c));
- tree nc = *pc;
- tree data[2] = { c, nc };
- walk_tree_without_duplicates (&OMP_CLAUSE_REDUCTION_INIT (nc),
- replace_reduction_placeholders,
- data);
- walk_tree_without_duplicates (&OMP_CLAUSE_REDUCTION_MERGE (nc),
- replace_reduction_placeholders,
- data);
+
+ hash_map<tree, tree> decl_map;
+ decl_map.put (OMP_CLAUSE_DECL (c), OMP_CLAUSE_DECL (c));
+ decl_map.put (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c),
+ OMP_CLAUSE_REDUCTION_PLACEHOLDER (*pc));
+ if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (*pc))
+ decl_map.put (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c),
+ OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (*pc));
+
+ copy_body_data id;
+ memset (&id, 0, sizeof (id));
+ id.src_fn = current_function_decl;
+ id.dst_fn = current_function_decl;
+ id.src_cfun = cfun;
+ id.decl_map = &decl_map;
+ id.copy_decl = copy_decl_no_change;
+ id.transform_call_graph_edges = CB_CGE_DUPLICATE;
+ id.transform_new_cfg = true;
+ id.transform_return_to_modify = false;
+ id.transform_lang_insert_block = NULL;
+ id.eh_lp_nr = 0;
+ walk_tree (&OMP_CLAUSE_REDUCTION_INIT (*pc), copy_tree_body_r,
+ &id, NULL);
+ walk_tree (&OMP_CLAUSE_REDUCTION_MERGE (*pc), copy_tree_body_r,
+ &id, NULL);
+
+ tree d;
+ unsigned i;
+ FOR_EACH_VEC_ELT (no_context_vars, i, d)
+ {
+ DECL_CONTEXT (d) = NULL_TREE;
+ DECL_CONTEXT (*decl_map.get (d)) = NULL_TREE;
+ }
+ }
+ else
+ {
+ OMP_CLAUSE_REDUCTION_INIT (*pc)
+ = unshare_expr (OMP_CLAUSE_REDUCTION_INIT (c));
+ OMP_CLAUSE_REDUCTION_MERGE (*pc)
+ = unshare_expr (OMP_CLAUSE_REDUCTION_MERGE (c));
}
pc = &OMP_CLAUSE_CHAIN (*pc);
break;
diff --git a/gcc/testsuite/c-c++-common/gomp/pr102431.c b/gcc/testsuite/c-c++-common/gomp/pr102431.c
new file mode 100644
index 00000000000..bf4f3cb71b3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr102431.c
@@ -0,0 +1,16 @@
+/* PR middle-end/102431 */
+
+struct S { int s; } s;
+void add (struct S *, struct S *);
+void init (struct S *);
+void bar (int i, struct S *);
+#pragma omp declare reduction (+:struct S:add (&omp_out, &omp_in)) initializer (init (&omp_priv))
+
+void
+foo (void)
+{
+ int i;
+ #pragma omp loop bind(teams) reduction(+:s)
+ for (i = 0; i < 8; i++)
+ bar (i, &s);
+}
diff --git a/gcc/testsuite/g++.dg/gomp/pr102431.C b/gcc/testsuite/g++.dg/gomp/pr102431.C
new file mode 100644
index 00000000000..7db36f48540
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/pr102431.C
@@ -0,0 +1,13 @@
+// PR middle-end/102431
+
+struct S { S (); ~S (); S (const S &); void add (const S &); int s; } s;
+void bar (int, S &);
+#pragma omp declare reduction (+:S:omp_out.add (omp_in))
+
+void
+foo ()
+{
+ #pragma omp loop bind(teams) reduction(+:s)
+ for (int i = 0; i < 8; i++)
+ bar (i, s);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-10 8:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 8:21 [gcc r10-10657] openmp: Fix up handling of reduction clauses on the loop construct [PR102431] Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).