Ignore reduction clauses in kernels region
2015-09-29 Tom de Vries <tom@codesourcery.com>
* omp-low.c (ctx_in_oacc_kernels_region): New function.
(scan_omp_for): Filter out reduction clauses in kernels region.
* c-c++-common/goacc/kernels-acc-loop-reduction.c: New test.
---
gcc/omp-low.c | 18 +++++++++++++++-
.../goacc/kernels-acc-loop-reduction.c | 25 ++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/c-c++-common/goacc/kernels-acc-loop-reduction.c
@@ -2579,6 +2579,20 @@ oacc_loop_or_target_p (gimple *stmt)
&& gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_OACC_LOOP));
}
+bool
+ctx_in_oacc_kernels_region (omp_context *ctx)
+{
+ for (;ctx != NULL; ctx = ctx->outer)
+ {
+ gimple *stmt = ctx->stmt;
+ if (gimple_code (stmt) == GIMPLE_OMP_TARGET
+ && gimple_omp_target_kind (stmt) == GF_OMP_TARGET_KIND_OACC_KERNELS)
+ return true;
+ }
+
+ return false;
+}
+
/* Scan a GIMPLE_OMP_FOR. */
static void
@@ -2592,6 +2606,7 @@ scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
bool auto_clause = false;
bool seq_clause = false;
int gwv_routine = 0;
+ bool in_oacc_kernels_region = ctx_in_oacc_kernels_region (outer_ctx);
if (outer_ctx)
outer_type = gimple_code (outer_ctx->stmt);
@@ -2665,7 +2680,8 @@ scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
/* Filter out any OpenACC clauses which aren't associated with
gangs, workers or vectors. Such reductions are no-ops. */
- if (extract_oacc_loop_mask (ctx) == 0)
+ if (extract_oacc_loop_mask (ctx) == 0
+ || in_oacc_kernels_region)
{
/* First filter out the clauses at the beginning of the chain. */
while (clauses && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_REDUCTION)
new file mode 100644
@@ -0,0 +1,25 @@
+/* { dg-additional-options "-O2" } */
+/* { dg-additional-options "-ftree-parallelize-loops=32" } */
+/* { dg-additional-options "-fdump-tree-parloops_oacc_kernels-all" } */
+/* { dg-additional-options "-fdump-tree-optimized" } */
+
+unsigned int
+foo (int n, unsigned int *a)
+{
+ unsigned int sum = 0;
+
+#pragma acc kernels loop gang reduction(+:sum)
+ for (int i = 0; i < n; i++)
+ sum += a[i];
+
+ return sum;
+}
+
+/* Check that only one loop is analyzed, and that it can be parallelized. */
+/* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 1 "parloops_oacc_kernels" } } */
+/* { dg-final { scan-tree-dump-not "FAILED:" "parloops_oacc_kernels" } } */
+
+/* Check that the loop has been split off into a function. */
+/* { dg-final { scan-tree-dump-times "(?n);; Function .*foo.*\\._omp_fn\\.0" 1 "optimized" } } */
+
+/* { dg-final { scan-tree-dump-times "(?n)pragma omp target oacc_parallel.*num_gangs\\(32\\)" 1 "parloops_oacc_kernels" } } */
--
1.9.1