public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-9402] openmp: Don't optimize shared to firstprivate on task with depend clause Date: Tue, 20 Apr 2021 23:30:52 +0000 (GMT) [thread overview] Message-ID: <20210420233052.E79153AA8CBD@sourceware.org> (raw) https://gcc.gnu.org/g:8313557e2714f710247372caa8b473e292ebff42 commit r9-9402-g8313557e2714f710247372caa8b473e292ebff42 Author: Jakub Jelinek <jakub@redhat.com> Date: Fri Dec 18 21:43:20 2020 +0100 openmp: Don't optimize shared to firstprivate on task with depend clause The attached testcase is miscompiled, because we optimize shared clauses to firstprivate when task body can't modify the variable even when the task has depend clause. That is wrong, because firstprivate means the variable will be copied immediately when the task is created, while with depend clause some other task might change it later before the dependencies are satisfied and the task should observe the value only after the change. 2020-12-18 Jakub Jelinek <jakub@redhat.com> * gimplify.c (struct gimplify_omp_ctx): Add has_depend member. (gimplify_scan_omp_clauses): Set it to true if OMP_CLAUSE_DEPEND appears on OMP_TASK. (gimplify_adjust_omp_clauses_1, gimplify_adjust_omp_clauses): Force GOVD_WRITTEN on shared variables if task construct has depend clause. * testsuite/libgomp.c/task-6.c: New test. (cherry picked from commit 99ddd36e800a24fcb744a14ff9adabb0a7ef72c8) Diff: --- gcc/gimplify.c | 12 +++++++++ libgomp/testsuite/libgomp.c/task-6.c | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index e103e76b466..8c30910d90d 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -211,6 +211,7 @@ struct gimplify_omp_ctx bool distribute; bool target_firstprivatize_array_bases; bool add_safelen1; + bool has_depend; int defaultmap[4]; }; @@ -8886,6 +8887,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, remove = true; break; } + if (code == OMP_TASK) + ctx->has_depend = true; break; case OMP_CLAUSE_TO: @@ -9503,6 +9506,11 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) return 0; } code = OMP_CLAUSE_SHARED; + /* Don't optimize shared into firstprivate for read-only vars + on tasks with depend clause, we shouldn't try to copy them + until the dependencies are satisfied. */ + if (gimplify_omp_ctxp->has_depend) + flags |= GOVD_WRITTEN; } else if (flags & GOVD_PRIVATE) code = OMP_CLAUSE_PRIVATE; @@ -9750,6 +9758,10 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p, OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_PRIVATE); OMP_CLAUSE_PRIVATE_DEBUG (c) = 1; } + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED + && ctx->has_depend + && DECL_P (decl)) + n->value |= GOVD_WRITTEN; if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED && (n->value & GOVD_WRITTEN) == 0 && DECL_P (decl) diff --git a/libgomp/testsuite/libgomp.c/task-6.c b/libgomp/testsuite/libgomp.c/task-6.c new file mode 100644 index 00000000000..e5fc758d283 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/task-6.c @@ -0,0 +1,47 @@ +#include <stdlib.h> +#include <unistd.h> + +int +main () +{ + int x = 0, y = 0; + #pragma omp parallel shared(x, y) + #pragma omp master + { + #pragma omp task depend(out:y) shared(x, y) + { + sleep (1); + x = 1; + y = 1; + } + #pragma omp task depend(inout:y) shared(x, y) + { + if (x != 1 || y != 1) + abort (); + y++; + } + } + if (x != 1 || y != 2) + abort (); + x = 0; + y = 0; + #pragma omp parallel + #pragma omp master + { + #pragma omp task depend(out:y) + { + sleep (1); + x = 1; + y = 1; + } + #pragma omp task depend(inout:y) + { + if (x != 1 || y != 1) + abort (); + y++; + } + } + if (x != 1 || y != 2) + abort (); + return 0; +}
reply other threads:[~2021-04-20 23:30 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210420233052.E79153AA8CBD@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).