From: Tom de Vries <Tom_deVries@mentor.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PR65637][PATCH][4/5] Fix inner loop phi in expand_omp_for_static_chunk
Date: Mon, 31 Aug 2015 12:03:00 -0000 [thread overview]
Message-ID: <55E441CA.9070900@mentor.com> (raw)
In-Reply-To: <552E64EC.5060707@mentor.com>
[-- Attachment #1: Type: text/plain, Size: 995 bytes --]
[ was: Re: [PR65637][PATCH][2/3] Fix inner loop phi in
expand_omp_for_static_chunk ]
On 15/04/15 15:17, Tom de Vries wrote:
> On 15-04-15 15:10, Tom de Vries wrote:
>> Hi,
>>
>> This patch series fixes PR65637.
>>
<SNIP>
>
> This patch fixes an libgomp.c/autopar-1.c execution failure.
>
> For autopar-1.c, the original loop has a loop phi:
> ...
> # s.5_20 = PHI <s.5_12(4), 0.0(20)>
> ...
>
> After expand_omp_for_static_chunk, there's an inner and an outer loop.
> The outer
> loop phi is:
> ...
> # s.5_11 = PHI <0.0(15), s.5_12(21)>
> ...
>
> and the inner loop phi is:
> ...
> # s.5_20 = PHI <s.5_12(4), 0.0(20)>
> ...
>
> The inner loop phi should not have 0.0 as argument, but the result of
> the outer
> loop phi, like this:
> ...
> # s.5_20 = PHI <s.5_12(4), s.5_11(20)>
> ...
>
> This patch fixes the inner loop phi, and allows the autopar-1.c
> execution test
> to pass.
>
This updated patch includes a test-case. It also handles simple latches.
OK for trunk?
Thanks,
- Tom
[-- Attachment #2: 0004-Fix-inner-loop-phi-in-expand_omp_for_static_chunk.patch --]
[-- Type: text/x-patch, Size: 3725 bytes --]
Fix inner loop phi in expand_omp_for_static_chunk
2015-08-31 Tom de Vries <tom@codesourcery.com>
PR tree-optimization/65637
* omp-low.c (find_phi_with_arg_on_edge): New function.
(expand_omp_for_static_chunk): Fix inner loop phi.
* testsuite/libgomp.c/autopar-1-chunk-size.c: New test.
---
gcc/ChangeLog | 6 +++
gcc/omp-low.c | 30 ++++++++++++++-
libgomp/testsuite/libgomp.c/autopar-1-chunk-size.c | 44 ++++++++++++++++++++++
3 files changed, 79 insertions(+), 1 deletion(-)
create mode 100644 libgomp/testsuite/libgomp.c/autopar-1-chunk-size.c
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5a273ba..a14564c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,12 @@
2015-05-18 Tom de Vries <tom@codesourcery.com>
PR tree-optimization/65637
+ * omp-low.c (find_phi_with_arg_on_edge): New function.
+ (expand_omp_for_static_chunk): Fix inner loop phi.
+
+2015-05-18 Tom de Vries <tom@codesourcery.com>
+
+ PR tree-optimization/65637
* omp-low.c (expand_omp_for_static_chunk): Fix gcc_assert for the case
that head is NULL.
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 4e732ae..e2be7c7 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -6885,6 +6885,22 @@ expand_omp_for_static_nochunk (struct omp_region *region,
}
}
+static gphi *
+find_phi_with_arg_on_edge (tree arg, edge e)
+{
+ basic_block bb = e->dest;
+
+ for (gphi_iterator gpi = gsi_start_phis (bb);
+ !gsi_end_p (gpi);
+ gsi_next (&gpi))
+ {
+ gphi *phi = gpi.phi ();
+ if (PHI_ARG_DEF_FROM_EDGE (phi, e) == arg)
+ return phi;
+ }
+
+ return NULL;
+}
/* A subroutine of expand_omp_for. Generate code for a parallel
loop with static schedule and a specified chunk size. Given
@@ -7324,7 +7340,19 @@ expand_omp_for_static_chunk (struct omp_region *region,
t = vextra;
add_phi_arg (nphi, t, ene, locus);
locus = redirect_edge_var_map_location (vm);
- add_phi_arg (nphi, redirect_edge_var_map_def (vm), re, locus);
+ tree back_arg = redirect_edge_var_map_def (vm);
+ add_phi_arg (nphi, back_arg, re, locus);
+ edge ce = find_edge (cont_bb, body_bb);
+ if (ce == NULL)
+ {
+ ce = BRANCH_EDGE (cont_bb);
+ gcc_assert (single_succ (ce->dest) == body_bb);
+ ce = single_succ_edge (ce->dest);
+ }
+ gphi *inner_loop_phi = find_phi_with_arg_on_edge (back_arg, ce);
+ gcc_assert (inner_loop_phi != NULL);
+ add_phi_arg (inner_loop_phi, gimple_phi_result (nphi),
+ find_edge (seq_start_bb, body_bb), locus);
}
gcc_assert (gsi_end_p (psi) && (head == NULL || i == head->length ()));
redirect_edge_var_map_clear (re);
diff --git a/libgomp/testsuite/libgomp.c/autopar-1-chunk-size.c b/libgomp/testsuite/libgomp.c/autopar-1-chunk-size.c
new file mode 100644
index 0000000..5a36474
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/autopar-1-chunk-size.c
@@ -0,0 +1,44 @@
+/* { dg-do run } */
+/* { dg-additional-options "-ftree-parallelize-loops=4 -ffast-math --param parloops-chunk-size=100" } */
+
+extern void abort (void);
+
+double d[1024], e[1024];
+int f[1024], g[1024];
+
+double __attribute__((noinline))
+foo (void)
+{
+ double s = 0.0;
+ int i;
+ for (i = 0; i < 1024; i++)
+ s += d[i] - e[i];
+ return s;
+}
+
+int __attribute__((noinline))
+bar (void)
+{
+ int s = 0, i;
+ for (i = 0; i < 1024; i++)
+ s += f[i] - g[i];
+ return s;
+}
+
+int
+main (void)
+{
+ int i;
+ for (i = 0; i < 1024; i++)
+ {
+ d[i] = i * 2;
+ e[i] = i;
+ f[i] = i * 2;
+ g[i] = i;
+ }
+ if (foo () != 1023 * 1024 / 2)
+ abort ();
+ if (bar () != 1023 * 1024 / 2)
+ abort ();
+ return 0;
+}
--
1.9.1
next prev parent reply other threads:[~2015-08-31 12:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-15 13:10 [PR65637] Fix ssa-handling code " Tom de Vries
2015-04-15 13:15 ` [PR65637][PATCH][1/3] Fix gcc_assert " Tom de Vries
2015-08-31 12:00 ` [PR65637][PATCH][3/5] " Tom de Vries
2015-09-03 9:16 ` Jakub Jelinek
2015-04-15 13:17 ` [PR65637][PATCH][2/3] Fix inner loop phi " Tom de Vries
2015-08-31 12:03 ` Tom de Vries [this message]
2015-09-03 9:20 ` [PR65637][PATCH][4/5] " Jakub Jelinek
2015-04-15 13:23 ` [PR65637][PATCH][3/3] Handle 2 preds for fin_bb " Tom de Vries
2015-08-31 12:26 ` [PR65637][PATCH][5/5] " Tom de Vries
2015-09-03 9:40 ` Jakub Jelinek
2015-05-18 13:13 ` [PING][PR65637] Fix ssa-handling code " Tom de Vries
2015-05-18 14:19 ` Tom de Vries
2015-06-08 12:34 ` [PING^2][PR65637] " Tom de Vries
2015-08-31 11:44 ` [PR65637] " Tom de Vries
2015-08-31 11:51 ` [PATCH][1/5] Add param parloops-chunk-size Tom de Vries
2015-09-03 8:57 ` Jakub Jelinek
2015-08-31 11:55 ` [PATCH][2/5] Handle simple latch bb in expand_omp_for_static_chunk Tom de Vries
2015-09-03 9:02 ` 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=55E441CA.9070900@mentor.com \
--to=tom_devries@mentor.com \
--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).