From: Tobias Burnus <tobias@codesourcery.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
fortran <fortran@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>
Subject: [Patch] openmp: Map holds clause to IFN_ASSUME for Fortran
Date: Thu, 6 Oct 2022 12:55:01 +0200 [thread overview]
Message-ID: <e747364c-f716-1661-2570-590a4c47820c@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 489 bytes --]
Same as for C/C++, albeit a tiny bit longer patch.
I don't know whether it makes sense to handle – in the long run – the
case of se.pre/se.post being nonempty – and, if so, how.
OK for mainline?
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: omp-assumes-hold.diff --]
[-- Type: text/x-patch, Size: 3389 bytes --]
openmp: Map holds clause to IFN_ASSUME for Fortran
Same as r13-3107-g847f5addc4d07a2f3b95f5daa50ab4a64dfd957d did for C/C++.
Convert '!$omp assume holds(cond)' to IFN_ASSUME (cond).
gcc/fortran/
* trans-openmp.cc (gfc_trans_omp_assume): New.
(gfc_trans_omp_directive): Call it.
gcc/teststuite/
* gfortran.dg/gomp/assume-3.f90: New test.
gcc/fortran/trans-openmp.cc | 27 ++++++++++++++++-
gcc/testsuite/gfortran.dg/gomp/assume-3.f90 | 46 +++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 21053694f81..b82257258a7 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -4570,6 +4570,31 @@ gfc_trans_oacc_wait_directive (gfc_code *code)
static tree gfc_trans_omp_sections (gfc_code *, gfc_omp_clauses *);
static tree gfc_trans_omp_workshare (gfc_code *, gfc_omp_clauses *);
+static tree
+gfc_trans_omp_assume (gfc_code *code)
+{
+ stmtblock_t block;
+ gfc_init_block (&block);
+ gfc_omp_assumptions *assume = code->ext.omp_clauses->assume;
+ if (assume)
+ for (gfc_expr_list *el = assume->holds; el; el = el->next)
+ {
+ tree t;
+ gfc_se se;
+ gfc_init_se (&se, NULL);
+ gfc_conv_expr (&se, el->expr);
+ /* Avoid side effects. */
+ if (se.pre.head || se.post.head)
+ continue;
+ t = build_call_expr_internal_loc (gfc_get_location (&el->expr->where),
+ IFN_ASSUME, void_type_node, 1,
+ se.expr);
+ gfc_add_expr_to_block (&block, t);
+ }
+ gfc_add_expr_to_block (&block, gfc_trans_omp_code (code->block->next, true));
+ return gfc_finish_block (&block);
+}
+
static tree
gfc_trans_omp_atomic (gfc_code *code)
{
@@ -7488,7 +7513,7 @@ gfc_trans_omp_directive (gfc_code *code)
switch (code->op)
{
case EXEC_OMP_ASSUME:
- return gfc_trans_omp_code (code->block->next, true);
+ return gfc_trans_omp_assume (code);
case EXEC_OMP_ATOMIC:
return gfc_trans_omp_atomic (code);
case EXEC_OMP_BARRIER:
diff --git a/gcc/testsuite/gfortran.dg/gomp/assume-3.f90 b/gcc/testsuite/gfortran.dg/gomp/assume-3.f90
new file mode 100644
index 00000000000..e5deace306e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/assume-3.f90
@@ -0,0 +1,46 @@
+! { dg-do compile }
+! { dg-options "-fopenmp -O2 -fdump-tree-optimized -fdump-tree-original" }
+
+! { dg-final { scan-tree-dump-times ".ASSUME \\(x == 42\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times ".ASSUME \\(x <= 41\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times ".ASSUME \\(y <= 6\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times ".ASSUME \\(y > 5\\);" 1 "original" } }
+
+! { dg-final { scan-tree-dump-times "return 42;" 3 "optimized" } }
+! { dg-final { scan-tree-dump-not "return -1;" "optimized" } }
+
+integer function foo (x)
+ implicit none
+ integer, value :: x
+ integer :: y
+ !$omp assume holds (x == 42)
+ y = x;
+ !$omp end assume
+ foo = y
+end
+
+integer function bar (x)
+ implicit none
+ integer, value :: x
+ !$omp assume holds (x < 42)
+ block
+ end block
+ if (x == 42) then
+ bar = -1
+ return
+ end if
+ bar = 42
+end
+
+integer function foobar (y)
+ implicit none
+ integer, value :: y
+ !$omp assume holds(y > 5) holds (y < 7)
+ block
+ if (y == 6) then
+ foobar = 42
+ return
+ end if
+ end block
+ foobar = -1
+end
next reply other threads:[~2022-10-06 10:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-06 10:55 Tobias Burnus [this message]
2022-10-06 12:17 ` Jakub Jelinek
2022-10-06 16:15 ` Tobias Burnus
2022-10-06 16:32 ` Jakub Jelinek
2022-10-10 7:40 ` [committed] openmp, fortran: Fix up IFN_ASSUME call Jakub Jelinek
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=e747364c-f716-1661-2570-590a4c47820c@codesourcery.com \
--to=tobias@codesourcery.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/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: link
Be 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).