Rework OpenACC nested reduction clause consistency checking (was: Re: [PATCH][committed] Warn about inconsistent OpenACC nested reduction clauses)

Message ID 7ff53a86-d2ec-21ea-d0f4-4e0b13986771@codesourcery.com
State Superseded
Headers show
Series
  • Rework OpenACC nested reduction clause consistency checking (was: Re: [PATCH][committed] Warn about inconsistent OpenACC nested reduction clauses)
Related show

Commit Message

Frederik Harwath Dec. 3, 2019, 11:16 a.m.
Hi Jakub,

On 08.11.19 07:41, Harwath, Frederik wrote:
> On 06.11.19 14:00, Jakub Jelinek wrote:

> [...]

>> I'm not sure it is a good idea to use a TREE_LIST in this case, vec would be

>> more natural, wouldn't it.

> 

> Yes.

> 

> [...]

>> If gimplifier is not the right spot, then use a splay tree + vector instead?

>> splay tree for the outer ones, vector for the local ones, and put into both

>> the clauses, so you can compare reduction code etc.

> 

> Sounds like a good idea. I am going to try that.


Below you can find a patch that reimplements the nested reductions check using
more appropriate data structures. As an additional benefit, the quality of the warnings
has also improved (see description below). I have checked the patch by running the testsuite on
x86_64-pc-linux-gnu.

Best regards,
Frederik

Patch

From 94ca786172afa7dab7630d75965bf6d6f0dd24e1 Mon Sep 17 00:00:00 2001
From: Frederik Harwath <frederik@codesourcery.com>
Date: Tue, 3 Dec 2019 10:38:01 +0100
Subject: [PATCH] Rework OpenACC nested reduction clause consistency checking

Revision 277875 of trunk introduced a consistency check for nested OpenACC
reduction clauses. The implementation has two drawbacks:
1) It uses suboptimal data structures for storing information about
   the reduction clauses.
2) The warnings issued for *repeated* inconsistent use of reduction operators
   are confusing. For instance, on three nested loops that use the reduction
   operators +, -, + on the same variable, we obtain a warning at the switch
   from + to - (as desired) and another warning about the switch from - to +.
   It would be preferable to avoid the second warning since + is consistent
   with the first reduction operator.

This commit attempts to fix both problems by using more appropriate data
structures (splay trees and vectors instead of tree lists) for keeping track of
the information about the reduction clauses.

2019-12-3  Frederik Harwath  <frederik@codesourcery.com>

	gcc/
	* omp-low.c (omp_context): Removed fields local_reduction_clauses,
	outer_reduction_clauses; added fields oacc_reduction_clauses,
	oacc_reductions_stack.
	(oacc_reduction_clause_location): New struct.
	(oacc_reduction_var_occ): New struct.
	(new_omp_context): Adjust omp_context initialization to new fields.
	(delete_omp_context): Adjust omp_context deletion to new fields.
	(rewind_oacc_reductions_stack): New function.
	(check_oacc_reduction_clause): New function.
	(check_oacc_reduction_clauses): New function.
	(scan_sharing_clauses): Call check_oacc_reduction_clause for
	reduction clauses (this handles clauses on compute regions)
	if a new optional flag is enabled.
	(scan_omp_for): Remove old nested reduction check, call
	 check_oacc_reduction_clauses instead.
	(scan_omp_target): Adapt call to scan_sharing_clauses to enable the new
	flag.

   	gcc/testsuite/
	* c-c++-common/goacc/nested-reductions-warn.c: Add dg-prune-output to
	 ignore warnings that are not relevant to the test.
	(acc_parallel): Stop expecting pruned warnings, adjust expected
	warnings to changes in omp-low.c, add checks for info messages about the
	location of clauses.
	(acc_parallel_loop): Likewise.
	(acc_parallel_reduction): Likewise.
	(acc_parallel_loop_reduction): Likewise.
	(acc_routine): Likewise.
	(acc_kernels): Likewise.

	* gfortran.dg/goacc/nested-reductions-warn.f90: Likewise.
---
 gcc/omp-low.c                                 | 305 ++++++++++++------
 .../goacc/nested-reductions-warn.c            |  81 ++---
 .../goacc/nested-reductions-warn.f90          |  83 ++---
 3 files changed, 271 insertions(+), 198 deletions(-)

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 19132f76da2..ba04e7477dc 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -73,6 +73,9 @@  along with GCC; see the file COPYING3.  If not see
    scanned for regions which are then moved to a new
    function, to be invoked by the thread library, or offloaded.  */
 
+
+struct oacc_reduction_var_occ;
+
 /* Context structure.  Used to store information about each parallel
    directive in the code.  */
 
@@ -128,12 +131,6 @@  struct omp_context
      corresponding tracking loop iteration variables.  */
   hash_map<tree, tree> *lastprivate_conditional_map;
 
-  /* A tree_list of the reduction clauses in this context.  */
-  tree local_reduction_clauses;
-
-  /* A tree_list of the reduction clauses in outer contexts.  */
-  tree outer_reduction_clauses;
-
   /* Nesting depth of this context.  Used to beautify error messages re
      invalid gotos.  The outermost ctx is depth 1, with depth 0 being
      reserved for the main body of the function.  */
@@ -163,8 +160,52 @@  struct omp_context
 
   /* True if there is bind clause on the construct (i.e. a loop construct).  */
   bool loop_p;
+
+  /* A mapping that maps a variable to information about the last OpenACC
+     reduction clause that used the variable above the current context.
+     This information is used for checking the nesting restrictions for
+     reduction clauses by the function check_oacc_reduction_clauses.
+     The mapping is owned by the outermost context (i.e. a context which
+     has no outer context) and shared with all contexts below.  */
+  splay_tree oacc_reduction_clauses;
+
+  /* A vector that is used as a stack to keep track of which context last
+     contained an OpenACC reduction clause for which variable during the check
+     performed by check_oacc_reduction_clauses.
+     The vector is owned by the outermost context and shared with all contexts
+     below.  */
+  vec<oacc_reduction_var_occ*> *oacc_reductions_stack;
+};
+
+/* The value type in omp_context's oacc_reduction_clauses splay tree.  */
+
+struct oacc_reduction_clause_location {
+  /* An OpenACC reduction clause.  */
+  tree clause;
+
+  /* A context that contains the reduction clause.  */
+  omp_context *ctx;
+};
+
+/* Information about the occurrence of an OpenACC reduction variable in an
+   omp_context that is used to restore the last valid reduction clause
+   location in check_oacc_reduction_clauses when moving upwards in the context
+   tree.  */
+
+struct oacc_reduction_var_occ {
+  /* A variable that occurs in an OpenACC reduction clause.  */
+  tree var;
+
+  /* The depth of the context that contained the reduction clause for the
+     variable.  */
+  int depth;
+
+  /* The last enclosing context of the context in which the variable
+     occurred that also contained a reduction clause for the variable.  */
+  omp_context *ctx;
 };
 
+
 static splay_tree all_contexts;
 static int taskreg_nesting_level;
 static int target_nesting_level;
@@ -909,7 +950,6 @@  static omp_context *
 new_omp_context (gimple *stmt, omp_context *outer_ctx)
 {
   omp_context *ctx = XCNEW (omp_context);
-
   splay_tree_insert (all_contexts, (splay_tree_key) stmt,
 		     (splay_tree_value) ctx);
   ctx->stmt = stmt;
@@ -919,9 +959,9 @@  new_omp_context (gimple *stmt, omp_context *outer_ctx)
       ctx->outer = outer_ctx;
       ctx->cb = outer_ctx->cb;
       ctx->cb.block = NULL;
-      ctx->local_reduction_clauses = NULL;
-      ctx->outer_reduction_clauses = ctx->outer_reduction_clauses;
       ctx->depth = outer_ctx->depth + 1;
+      ctx->oacc_reduction_clauses = outer_ctx->oacc_reduction_clauses;
+      ctx->oacc_reductions_stack = outer_ctx->oacc_reductions_stack;
     }
   else
     {
@@ -936,9 +976,12 @@  new_omp_context (gimple *stmt, omp_context *outer_ctx)
       ctx->cb.transform_call_graph_edges = CB_CGE_MOVE;
       ctx->cb.adjust_array_error_bounds = true;
       ctx->cb.dont_remap_vla_if_no_change = true;
-      ctx->local_reduction_clauses = NULL;
-      ctx->outer_reduction_clauses = NULL;
       ctx->depth = 1;
+      ctx->oacc_reduction_clauses = splay_tree_new (splay_tree_compare_pointers,
+						    NULL,
+						    splay_tree_delete_pointers);
+      ctx->oacc_reductions_stack = new vec<oacc_reduction_var_occ*>;
+      ctx->oacc_reductions_stack->create(5);
     }
 
   ctx->cb.decl_map = new hash_map<tree, tree>;
@@ -1025,6 +1068,20 @@  delete_omp_context (splay_tree_value value)
 
   delete ctx->lastprivate_conditional_map;
 
+  if (!ctx->outer)
+    {
+      /* Delete data structures used by oacc_check_reduction_clauses only when
+	 reaching an outermost context.  */
+      splay_tree_delete(ctx->oacc_reduction_clauses);
+
+      vec<oacc_reduction_var_occ*> *reductions = ctx->oacc_reductions_stack;
+      oacc_reduction_var_occ *occ;
+      for (size_t i = 0; reductions->iterate (i, &occ); ++i)
+	  XDELETE (occ);
+      reductions->release ();
+      delete reductions;
+    }
+
   XDELETE (ctx);
 }
 
@@ -1086,11 +1143,141 @@  fixup_child_record_type (omp_context *ctx)
     = build_qualified_type (build_reference_type (type), TYPE_QUAL_RESTRICT);
 }
 
-/* Instantiate decls as necessary in CTX to satisfy the data sharing
-   specified by CLAUSES.  */
+/*  Restore the information about OpenACC reduction clauses that
+    is valid for the given context.  */
+
+static void
+rewind_oacc_reductions_stack (omp_context *ctx)
+{
+  vec<oacc_reduction_var_occ*>* stack = ctx->oacc_reductions_stack;
+  splay_tree reduction_clauses = ctx->oacc_reduction_clauses;
+
+  if (!stack->is_empty ())
+    {
+      unsigned removed_count = 0;
+
+      /* Since we are moving top-down through the contexts, information about
+	 reduction clauses that occurred in contexts whose depth is greater than
+	 ctx->depth is no longer valid. Remove corresponding elements from the
+	 stack and recover last valid locations of the reduction clauses.  */
+      oacc_reduction_var_occ** occ_ptr;
+      for (occ_ptr = stack->end () - 1; occ_ptr >= stack->begin (); --occ_ptr)
+	{
+	  oacc_reduction_var_occ* occ = *occ_ptr;
+
+	  if (occ->depth < ctx->depth)
+	    break;
+
+	  splay_tree_key var_key = (splay_tree_key)occ->var;
+	  if (occ->ctx)
+	    {
+	      splay_tree_node n = splay_tree_lookup (reduction_clauses, var_key);
+	      oacc_reduction_clause_location* l =
+		(oacc_reduction_clause_location*)n->value;
+	      l->ctx = occ->ctx;
+	    }
+	  else
+	      splay_tree_remove (reduction_clauses, var_key);
+
+	  XDELETE (occ);
+	  ++removed_count;
+	}
+
+      stack->truncate (stack->length () - removed_count);
+    }
+}
+
+/* Check that the OpenACC reduction clause meets the restrictions
+   of OpenACC 2.6, section 2.9.11 and warn if it does not.
+   If the variable in the clause occurred in a clause in an enclosing context of
+   the current context, then
+     - the reduction operation in the clause must agree with the operation in
+       the previous clause, and
+     - all contexts between the current and the previous context must contain a
+       reduction clause for the variable.  */
+
+static void
+check_oacc_reduction_clause(tree clause, omp_context *ctx)
+{
+  if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_REDUCTION)
+    return;
+
+  splay_tree reduction_clauses = ctx->oacc_reduction_clauses;
+  tree var = OMP_CLAUSE_DECL (clause);
+
+  /* Push information about the reduction variable occurrence onto a stack.
+     This allows us to recover the location of the last valid clause
+     for the reduction variable when moving up the context tree later.  */
+  oacc_reduction_var_occ* occ = XCNEW (oacc_reduction_var_occ);
+  occ->var = var;
+  occ->depth = ctx->depth;
+  ctx->oacc_reductions_stack->safe_push (occ);
+
+  /* Check if the variable has been used in a reduction clause in an enclosing
+     context before.  */
+  splay_tree_node var_node = reduction_clauses ?
+    splay_tree_lookup (reduction_clauses, (splay_tree_key)var) : NULL;
+
+  oacc_reduction_clause_location* clause_loc = NULL;
+  if (var_node)
+    {
+      /* Found a previous use of the reduction variable.  Check if the use in the
+	 current clause is consistent with it.  */
+      clause_loc = (oacc_reduction_clause_location*)var_node->value;
+
+      tree_code op = OMP_CLAUSE_REDUCTION_CODE (clause);
+      tree_code previous_op = OMP_CLAUSE_REDUCTION_CODE (clause_loc->clause);
+      if (op != previous_op)
+	{
+	  /* FIXME: Use the clause location instead of the statement.
+	     This does not yield the correct result for Fortran right now.  */
+	  warning_at (gimple_location (ctx->stmt), 0,
+		      "conflicting reduction operations for %qE", var);
+	  inform (OMP_CLAUSE_LOCATION (clause_loc->clause),
+		  "location of the previous reduction for %qE", var);
+	}
+
+      omp_context *prev_ctx = clause_loc->ctx;
+      occ->ctx = prev_ctx;
+
+      /* Walk up the context tree until the last context containing a reduction
+	 clause for that variable is found and complain about all intervening
+	 contexts that do not have such a reduction.  */
+      for (omp_context *c = ctx->outer; c != NULL && c != prev_ctx; c = c->outer)
+	warning_at (gimple_location (c->stmt), 0,
+		    "nested loop in reduction needs reduction clause for %qE",
+		    var);
+    }
+  else
+    {
+      /* This is the first reduction clause containing this variable in or above
+	 the current context.  Record its location.  */
+      clause_loc = XNEW (oacc_reduction_clause_location);
+      splay_tree_insert (reduction_clauses, (splay_tree_key)var,
+			 (splay_tree_value)clause_loc);
+      clause_loc->clause = clause;
+      occ->ctx = NULL;
+    }
+
+  clause_loc->ctx = ctx;
+}
+
+static void
+check_oacc_reduction_clauses (gomp_for *stmt, omp_context* ctx)
+{
+  rewind_oacc_reductions_stack (ctx);
+
+  for (tree c = gimple_omp_for_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c))
+      check_oacc_reduction_clause (c, ctx);
+}
+
+/* Instantiate decls as necessary in CTX to satisfy the data sharing specified
+   by CLAUSES.  The reduction clauses in OpenACC compute regions are also
+   checked by this function if the corresponding flag is set.  */
 
 static void
-scan_sharing_clauses (tree clauses, omp_context *ctx)
+scan_sharing_clauses (tree clauses, omp_context *ctx,
+		      bool check_oacc_reductions = false)
 {
   tree c, decl;
   bool scan_array_reductions = false;
@@ -1152,11 +1339,9 @@  scan_sharing_clauses (tree clauses, omp_context *ctx)
 	  goto do_private;
 
 	case OMP_CLAUSE_REDUCTION:
-	  if (is_oacc_parallel_or_serial (ctx) || is_oacc_kernels (ctx))
-	    ctx->local_reduction_clauses
-	      = tree_cons (NULL, c, ctx->local_reduction_clauses);
+	  if (check_oacc_reductions)
+	    check_oacc_reduction_clause (c, ctx);
 	  /* FALLTHRU */
-
 	case OMP_CLAUSE_IN_REDUCTION:
 	  decl = OMP_CLAUSE_DECL (c);
 	  if (TREE_CODE (decl) == MEM_REF)
@@ -2442,87 +2627,7 @@  scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
 	  check_oacc_kernel_gwv (stmt, ctx);
 	}
 
-      /* Collect all variables named in reductions on this loop.  Ensure
-	 that, if this loop has a reduction on some variable v, and there is
-	 a reduction on v somewhere in an outer context, then there is a
-	 reduction on v on all intervening loops as well.  */
-      tree local_reduction_clauses = NULL;
-      for (tree c = gimple_omp_for_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c))
-	{
-	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
-	    local_reduction_clauses
-	      = tree_cons (NULL, c, local_reduction_clauses);
-	}
-      if (ctx->outer_reduction_clauses == NULL && ctx->outer != NULL)
-	ctx->outer_reduction_clauses
-	  = chainon (unshare_expr (ctx->outer->local_reduction_clauses),
-		     ctx->outer->outer_reduction_clauses);
-      tree outer_reduction_clauses = ctx->outer_reduction_clauses;
-      tree local_iter = local_reduction_clauses;
-      for (; local_iter; local_iter = TREE_CHAIN (local_iter))
-	{
-	  tree local_clause = TREE_VALUE (local_iter);
-	  tree local_var = OMP_CLAUSE_DECL (local_clause);
-	  tree_code local_op = OMP_CLAUSE_REDUCTION_CODE (local_clause);
-	  bool have_outer_reduction = false;
-	  tree ctx_iter = outer_reduction_clauses;
-	  for (; ctx_iter; ctx_iter = TREE_CHAIN (ctx_iter))
-	    {
-	      tree outer_clause = TREE_VALUE (ctx_iter);
-	      tree outer_var = OMP_CLAUSE_DECL (outer_clause);
-	      tree_code outer_op = OMP_CLAUSE_REDUCTION_CODE (outer_clause);
-	      if (outer_var == local_var && outer_op != local_op)
-		{
-		  warning_at (gimple_location (stmt), 0,
-			      "conflicting reduction operations for %qE",
-			      local_var);
-		  inform (OMP_CLAUSE_LOCATION (outer_clause),
-			  "location of the previous reduction for %qE",
-			  outer_var);
-		}
-	      if (outer_var == local_var)
-		{
-		  have_outer_reduction = true;
-		  break;
-		}
-	    }
-	  if (have_outer_reduction)
-	    {
-	      /* There is a reduction on outer_var both on this loop and on
-		 some enclosing loop.  Walk up the context tree until such a
-		 loop with a reduction on outer_var is found, and complain
-		 about all intervening loops that do not have such a
-		 reduction.  */
-	      struct omp_context *curr_loop = ctx->outer;
-	      bool found = false;
-	      while (curr_loop != NULL)
-		{
-		  tree curr_iter = curr_loop->local_reduction_clauses;
-		  for (; curr_iter; curr_iter = TREE_CHAIN (curr_iter))
-		    {
-		      tree curr_clause = TREE_VALUE (curr_iter);
-		      tree curr_var = OMP_CLAUSE_DECL (curr_clause);
-		      if (curr_var == local_var)
-			{
-			  found = true;
-			  break;
-			}
-		    }
-		  if (!found)
-		    warning_at (gimple_location (curr_loop->stmt), 0,
-				"nested loop in reduction needs "
-				"reduction clause for %qE",
-				local_var);
-		  else
-		    break;
-		  curr_loop = curr_loop->outer;
-		}
-	    }
-	}
-      ctx->local_reduction_clauses = local_reduction_clauses;
-      ctx->outer_reduction_clauses
-	= chainon (unshare_expr (ctx->local_reduction_clauses),
-		   ctx->outer_reduction_clauses);
+      check_oacc_reduction_clauses (stmt, ctx);
     }
 
   scan_sharing_clauses (clauses, ctx);
@@ -2724,7 +2829,7 @@  scan_omp_target (gomp_target *stmt, omp_context *outer_ctx)
       gimple_omp_target_set_child_fn (stmt, ctx->cb.dst_fn);
     }
 
-  scan_sharing_clauses (clauses, ctx);
+  scan_sharing_clauses (clauses, ctx, true);
   scan_omp (gimple_omp_body_ptr (stmt), ctx);
 
   if (TYPE_FIELDS (ctx->record_type) == NULL)
diff --git a/gcc/testsuite/c-c++-common/goacc/nested-reductions-warn.c b/gcc/testsuite/c-c++-common/goacc/nested-reductions-warn.c
index e2af66e4fa3..e808c5c4c6d 100644
--- a/gcc/testsuite/c-c++-common/goacc/nested-reductions-warn.c
+++ b/gcc/testsuite/c-c++-common/goacc/nested-reductions-warn.c
@@ -1,5 +1,4 @@ 
 /* Test erroneous cases of nested reduction loops.  */
-
 void acc_parallel (void)
 {
   int i, j, k, l, sum, diff;
@@ -28,7 +27,6 @@  void acc_parallel (void)
       #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
           #pragma acc loop reduction(+:sum)
           for (l = 0; l < 10; l++)
@@ -37,8 +35,9 @@  void acc_parallel (void)
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
+      // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-3 }
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." } 
+        #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
           sum = 1;
 
@@ -46,31 +45,33 @@  void acc_parallel (void)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(-:sum)
+        #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
         for (k = 0; k < 10; k++)
           sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-7 }
+    // Should be reported twice, but dg-message does not allow to check this.
 
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
 	    sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
+        #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
 	    sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     #pragma acc loop reduction(+:sum) reduction(-:diff)
     for (i = 0; i < 10; i++)
@@ -102,7 +103,6 @@  void acc_parallel_loop (void)
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
         #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
@@ -111,7 +111,6 @@  void acc_parallel_loop (void)
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop collapse(2) // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
         for (k = 0; k < 10; k++)
           #pragma acc loop reduction(+:sum)
@@ -121,10 +120,8 @@  void acc_parallel_loop (void)
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
           #pragma acc loop reduction(+:sum)
           for (l = 0; l < 10; l++)
@@ -133,57 +130,52 @@  void acc_parallel_loop (void)
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." }
+        #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
           sum = 1;
 
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(-:sum)
+        #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
         for (k = 0; k < 10; k++)
           sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-7 }
 
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
 	    sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
+        #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
 	    sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     #pragma acc loop reduction(+:sum) reduction(-:diff)
     for (i = 0; i < 10; i++)
       {
         #pragma acc loop reduction(-:diff) // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (j = 0; j < 10; j++)
           #pragma acc loop reduction(+:sum)
           for (k = 0; k < 10; k++)
             sum = 1;
 
         #pragma acc loop reduction(+:sum) // { dg-warning "nested loop in reduction needs reduction clause for .diff." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (j = 0; j < 10; j++)
           #pragma acc loop reduction(-:diff)
           for (k = 0; k < 10; k++)
@@ -222,7 +214,6 @@  void acc_parallel_reduction (void)
       #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
           #pragma acc loop reduction(+:sum)
           for (l = 0; l < 10; l++)
@@ -232,7 +223,7 @@  void acc_parallel_reduction (void)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." }
+        #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
           sum = 1;
 
@@ -240,7 +231,7 @@  void acc_parallel_reduction (void)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(-:sum)
+        #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
         for (k = 0; k < 10; k++)
           sum = 1;
 
@@ -249,7 +240,6 @@  void acc_parallel_reduction (void)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
@@ -259,8 +249,7 @@  void acc_parallel_reduction (void)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
-      #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." })
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
+      #pragma acc loop reduction(+:sum)
 	for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
@@ -281,6 +270,7 @@  void acc_parallel_reduction (void)
           for (k = 0; k < 10; k++)
             diff = 1;
       }
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-80 }
   }
 }
 
@@ -296,7 +286,6 @@  void acc_parallel_loop_reduction (void)
     #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     for (i = 0; i < 10; i++)
       #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
         #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
@@ -305,7 +294,6 @@  void acc_parallel_loop_reduction (void)
     #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     for (i = 0; i < 10; i++)
       #pragma acc loop collapse(2) // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
         for (k = 0; k < 10; k++)
           #pragma acc loop reduction(+:sum)
@@ -315,10 +303,8 @@  void acc_parallel_loop_reduction (void)
     #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     for (i = 0; i < 10; i++)
       #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
           #pragma acc loop reduction(+:sum)
           for (l = 0; l < 10; l++)
@@ -327,28 +313,24 @@  void acc_parallel_loop_reduction (void)
     #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." }
+        #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
           sum = 1;
 
     #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(-:sum)
+        #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
         for (k = 0; k < 10; k++)
           sum = 1;
 
     #pragma acc loop reduction(max:sum) // { dg-warning "conflicting reduction operations for .sum." }
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
@@ -357,10 +339,8 @@  void acc_parallel_loop_reduction (void)
     #pragma acc loop reduction(max:sum) // { dg-warning "conflicting reduction operations for .sum." }
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
       for (j = 0; j < 10; j++)
-      #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." })
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
+      #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
@@ -370,19 +350,18 @@  void acc_parallel_loop_reduction (void)
     for (i = 0; i < 10; i++)
       {
         #pragma acc loop reduction(-:diff) // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (j = 0; j < 10; j++)
           #pragma acc loop reduction(+:sum)
           for (k = 0; k < 10; k++)
             sum = 1;
 
         #pragma acc loop reduction(+:sum) // { dg-warning "nested loop in reduction needs reduction clause for .diff." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (j = 0; j < 10; j++)
           #pragma acc loop reduction(-:diff)
           for (k = 0; k < 10; k++)
             diff = 1;
       }
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-81 }
   }
 }
 
@@ -415,7 +394,6 @@  void acc_routine (void)
       #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
 	for (k = 0; k < 10; k++)
           #pragma acc loop reduction(+:sum)
           for (l = 0; l < 10; l++)
@@ -424,8 +402,9 @@  void acc_routine (void)
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
+      // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-3 }
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." }
+        #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
           sum = 1;
 
@@ -433,31 +412,32 @@  void acc_routine (void)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
-        #pragma acc loop reduction(-:sum)
+        #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
         for (k = 0; k < 10; k++)
           sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-7 }
 
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
         #pragma acc loop // { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
 	    sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     #pragma acc loop reduction(+:sum)
     for (i = 0; i < 10; i++)
       #pragma acc loop reduction(-:sum) // { dg-warning "conflicting reduction operations for .sum." }
       for (j = 0; j < 10; j++)
-      #pragma acc loop reduction(+:sum) // { dg-warning "conflicting reduction operations for .sum." })
-      // { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 } 
+      #pragma acc loop reduction(+:sum)
         for (k = 0; k < 10; k++)
 	  #pragma acc loop reduction(*:sum) // { dg-warning "conflicting reduction operations for .sum." }
 	  for (l = 0; l < 10; l++)
 	    sum = 1;
+    // { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     #pragma acc loop reduction(+:sum) reduction(-:diff)
     for (i = 0; i < 10; i++)
@@ -523,3 +503,6 @@  void acc_kernels (void)
           sum = 1;
   }
 }
+
+/* Ignore warnings which are not related to what we try to test:
+   { dg-prune-output "insufficient partitioning available to parallelize loop" } */
diff --git a/gcc/testsuite/gfortran.dg/goacc/nested-reductions-warn.f90 b/gcc/testsuite/gfortran.dg/goacc/nested-reductions-warn.f90
index ec36bc9616e..893012f9240 100644
--- a/gcc/testsuite/gfortran.dg/goacc/nested-reductions-warn.f90
+++ b/gcc/testsuite/gfortran.dg/goacc/nested-reductions-warn.f90
@@ -34,7 +34,6 @@  subroutine acc_parallel ()
       !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(+:sum)
           do l = 1, 10
@@ -47,8 +46,9 @@  subroutine acc_parallel ()
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
+      ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-2 }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           sum = 1
         end do
@@ -59,19 +59,19 @@  subroutine acc_parallel ()
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
-        !$acc loop reduction(-:sum)
+        !$acc loop reduction(-:sum) ! { dg-warning "conflicting reduction operations for .sum." }
         do k = 1, 10
           sum = 1
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -80,13 +80,13 @@  subroutine acc_parallel ()
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-12 }
 
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -95,6 +95,7 @@  subroutine acc_parallel ()
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-12 }
 
     !$acc loop reduction(+:sum) reduction(-:diff)
     do i = 1, 10
@@ -128,7 +129,6 @@  subroutine acc_parallel_loop ()
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop reduction(+:sum)
         do k = 1, 10
@@ -140,7 +140,6 @@  subroutine acc_parallel_loop ()
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop collapse(2)  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         do k = 1, 10
           !$acc loop reduction(+:sum)
@@ -151,14 +150,11 @@  subroutine acc_parallel_loop ()
       end do
     end do
 
-
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(+:sum)
           do l = 1, 10
@@ -171,9 +167,9 @@  subroutine acc_parallel_loop ()
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+      ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-2 }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           sum = 1
         end do
@@ -183,22 +179,20 @@  subroutine acc_parallel_loop ()
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
-        !$acc loop reduction(-:sum)
+        !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
         do k = 1, 10
           sum = 1
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -207,14 +201,13 @@  subroutine acc_parallel_loop ()
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-12 }
 
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -223,11 +216,11 @@  subroutine acc_parallel_loop ()
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-12 }
 
     !$acc loop reduction(+:sum) reduction(-:diff)
     do i = 1, 10
       !$acc loop reduction(-:diff)  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop reduction(+:sum)
         do k = 1, 10
@@ -236,7 +229,6 @@  subroutine acc_parallel_loop ()
       end do
 
       !$acc loop reduction(+:sum)  ! { dg-warning "nested loop in reduction needs reduction clause for .diff." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop reduction(-:diff)
         do k = 1, 10
@@ -284,7 +276,6 @@  subroutine acc_parallel_reduction ()
       !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(+:sum)
           do l = 1, 10
@@ -298,7 +289,7 @@  subroutine acc_parallel_reduction ()
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           sum = 1
         end do
@@ -309,7 +300,7 @@  subroutine acc_parallel_reduction ()
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
-        !$acc loop reduction(-:sum)
+        !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
         do k = 1, 10
           sum = 1
         end do
@@ -321,7 +312,6 @@  subroutine acc_parallel_reduction ()
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -335,8 +325,7 @@  subroutine acc_parallel_reduction ()
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -364,6 +353,7 @@  subroutine acc_parallel_reduction ()
         end do
       end do
     end do
+  ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-107 }
   !$acc end parallel
 end subroutine acc_parallel_reduction
 
@@ -378,7 +368,6 @@  subroutine acc_parallel_loop_reduction ()
     !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     do i = 1, 10
       !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop reduction(+:sum)
         do k = 1, 10
@@ -390,7 +379,6 @@  subroutine acc_parallel_loop_reduction ()
     !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     do i = 1, 10
       !$acc loop collapse(2)  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         do k = 1, 10
           !$acc loop reduction(+:sum)
@@ -404,10 +392,8 @@  subroutine acc_parallel_loop_reduction ()
     !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     do i = 1, 10
       !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(+:sum)
           do l = 1, 10
@@ -420,9 +406,8 @@  subroutine acc_parallel_loop_reduction ()
     !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }  
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           sum = 1
         end do
@@ -432,9 +417,8 @@  subroutine acc_parallel_loop_reduction ()
     !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
-        !$acc loop reduction(-:sum)
+        !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
         do k = 1, 10
           sum = 1
         end do
@@ -444,10 +428,8 @@  subroutine acc_parallel_loop_reduction ()
     !$acc loop reduction(max:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -460,10 +442,8 @@  subroutine acc_parallel_loop_reduction ()
     !$acc loop reduction(max:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -476,7 +456,6 @@  subroutine acc_parallel_loop_reduction ()
     !$acc loop reduction(-:diff)  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
     do i = 1, 10
       !$acc loop reduction(-:diff)  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop reduction(+:sum)
         do k = 1, 10
@@ -485,7 +464,6 @@  subroutine acc_parallel_loop_reduction ()
       end do
 
       !$acc loop reduction(+:sum)  ! { dg-warning "nested loop in reduction needs reduction clause for .diff." }
-      ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
       do j = 1, 10
         !$acc loop reduction(-:diff)
         do k = 1, 10
@@ -493,6 +471,8 @@  subroutine acc_parallel_loop_reduction ()
         end do
       end do
     end do
+
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-109 }
   end do
 end subroutine acc_parallel_loop_reduction
 
@@ -531,7 +511,6 @@  subroutine acc_routine ()
       !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(+:sum)
           do l = 1, 10
@@ -544,8 +523,9 @@  subroutine acc_routine ()
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
+      ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-2 }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           sum = 1
         end do
@@ -556,19 +536,19 @@  subroutine acc_routine ()
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
-        !$acc loop reduction(-:sum)
+        !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
         do k = 1, 10
           sum = 1
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-9 }
 
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
         !$acc loop  ! { dg-warning "nested loop in reduction needs reduction clause for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -577,13 +557,13 @@  subroutine acc_routine ()
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-12 }
 
     !$acc loop reduction(+:sum)
     do i = 1, 10
       !$acc loop reduction(-:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
       do j = 1, 10
-        !$acc loop reduction(+:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
-        ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+        !$acc loop reduction(+:sum)
         do k = 1, 10
           !$acc loop reduction(*:sum)  ! { dg-warning "conflicting reduction operations for .sum." }
           do l = 1, 10
@@ -592,6 +572,7 @@  subroutine acc_routine ()
         end do
       end do
     end do
+    ! { dg-message "location of the previous reduction for .sum." "" { target *-*-* } .-12 }
 
     !$acc loop reduction(+:sum) reduction(-:diff)
     do i = 1, 10
@@ -672,3 +653,7 @@  subroutine acc_kernels ()
     end do
   !$acc end kernels
 end subroutine acc_kernels
+
+! Ignore warnings which are not related to what we try to test:
+! { dg-prune-output "insufficient partitioning available to parallelize loop" }
+
-- 
2.17.1