aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChung-Lin Tang <cltang@codesourcery.com>2016-08-17 12:08:30 +0000
committerChung-Lin Tang <cltang@codesourcery.com>2016-08-17 12:08:30 +0000
commited5ae3d5417e3856d87484132e1b9b76184d88bd (patch)
tree22f67221131bc8c5e54b3185038cc612ef12ab7f
parent6cd3f6c94d4a327458fe99fd51b1f6ab7d881316 (diff)
2016-08-17 Chung-Lin Tang <cltang@codesourcery.com>
* omp-low.c (lower_oacc_reductions): Adjust variable lookup to use maybe_lookup_decl, to handle nested acc loop directives. testsuite/ * c-c++-common/goacc/reduction-6.c: New testcase. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@239530 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/omp-low.c15
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/c-c++-common/goacc/reduction-6.c58
4 files changed, 79 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5142c920e8e..2f19c2585e1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2016-08-17 Chung-Lin Tang <cltang@codesourcery.com>
+
+ * omp-low.c (lower_oacc_reductions): Adjust variable lookup to use
+ maybe_lookup_decl, to handle nested acc loop directives.
+
2016-08-17 Richard Biener <rguenther@suse.de>
PR tree-optimization/76490
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 678c36ec307..3f7debf1fd1 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -5660,10 +5660,19 @@ lower_oacc_reductions (location_t loc, tree clauses, tree level, bool inner,
outgoing = var;
incoming = omp_reduction_init_op (loc, rcode, type);
}
- else if (ctx->outer)
- incoming = outgoing = lookup_decl (orig, ctx->outer);
else
- incoming = outgoing = orig;
+ {
+ /* Try to look at enclosing contexts for reduction var,
+ use original if no mapping found. */
+ tree t = NULL_TREE;
+ omp_context *c = ctx->outer;
+ while (c && !t)
+ {
+ t = maybe_lookup_decl (orig, c);
+ c = c->outer;
+ }
+ incoming = outgoing = (t ? t : orig);
+ }
has_outer_reduction:;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ed2ce1c12b3..0595ceb9d75 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2016-08-17 Chung-Lin Tang <cltang@codesourcery.com>
+
+ * c-c++-common/goacc/reduction-6.c: New testcase.
+
2016-08-17 Richard Biener <rguenther@suse.de>
PR tree-optimization/76490
diff --git a/gcc/testsuite/c-c++-common/goacc/reduction-6.c b/gcc/testsuite/c-c++-common/goacc/reduction-6.c
new file mode 100644
index 00000000000..619f82b9d8b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/reduction-6.c
@@ -0,0 +1,58 @@
+/* Check if different occurences of the reduction clause on
+ OpenACC loop nests will compile. */
+
+int foo (int N)
+{
+ int a = 0, b = 0, c = 0, d = 0, e = 0;
+
+ #pragma acc parallel
+ {
+ #pragma acc loop
+ for (int i = 0; i < N; i++)
+ {
+ #pragma acc loop reduction(+:a)
+ for (int j = 0; j < N; j++)
+ a += 1;
+ }
+ }
+
+ #pragma acc parallel
+ {
+ #pragma acc loop reduction(+:b)
+ for (int i = 0; i < N; i++)
+ {
+ #pragma acc loop
+ for (int j = 0; j < N; j++)
+ b += 1;
+ }
+ }
+
+ #pragma acc parallel
+ {
+ #pragma acc loop reduction(+:c)
+ for (int i = 0; i < N; i++)
+ {
+ #pragma acc loop reduction(+:c)
+ for (int j = 0; j < N; j++)
+ c += 1;
+ }
+ }
+
+ #pragma acc parallel loop
+ for (int i = 0; i < N; i++)
+ {
+ #pragma acc loop reduction(+:d)
+ for (int j = 0; j < N; j++)
+ d += 1;
+ }
+
+ #pragma acc parallel loop reduction(+:e)
+ for (int i = 0; i < N; i++)
+ {
+ #pragma acc loop reduction(+:e)
+ for (int j = 0; j < N; j++)
+ e += 1;
+ }
+
+ return a + b + c + d + e;
+}