diff mbox

[gomp4,committed] Ignore reduction clauses in kernels region

Message ID 560A5EC5.5060009@mentor.com
State New
Headers show

Commit Message

Tom de Vries Sept. 29, 2015, 9:49 a.m. UTC
Hi,

this patch filters out reduction clauses in an oacc kernels region. This 
fixes an ICE in the test-case.

Committed to gomp-4_0-branch.

Thanks,
- Tom
diff mbox

Patch

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

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index a5904eb..597035f 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.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)
diff --git a/gcc/testsuite/c-c++-common/goacc/kernels-acc-loop-reduction.c b/gcc/testsuite/c-c++-common/goacc/kernels-acc-loop-reduction.c
new file mode 100644
index 0000000..f3aa4e7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/kernels-acc-loop-reduction.c
@@ -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