working on another task, I found the idiom used in lower_oacc_loop_enter_exit rather confusing. I've applied this to use two different loops, clearly going in different directions, rather than a single loop and an internal mechanism to make one of the instances go backwards.

nathan
2015-09-14  Nathan Sidwell  <nat...@codesourcery.com>

	* omp-low.c (lower_oacc_loop_enter_exit): Use separate loops for
	entry and for exit.

Index: gcc/omp-low.c
===================================================================
--- gcc/omp-low.c	(revision 227683)
+++ gcc/omp-low.c	(working copy)
@@ -11182,41 +11182,34 @@ lower_omp_for_lastprivate (struct omp_fo
 
 static void
 lower_oacc_loop_enter_exit (bool enter_loop, tree clauses, gimple_seq *ilist,
-			     omp_context *ctx)
+			    omp_context *ctx)
 {
   unsigned loop_dim_mask = extract_oacc_loop_mask (ctx);
-  gimple_seq *seq;
-  enum internal_fn fork_join, f1, f2;
-  int dir;
 
   if (loop_dim_mask == 0)
     return;
 
   if (enter_loop)
     {
-      fork_join = IFN_GOACC_FORK;
-      f1 = IFN_GOACC_REDUCTION_SETUP;
-      f2 = IFN_GOACC_REDUCTION_INIT;
-      seq = &oacc_gang_reduction_init;
-      dir = 1;
+      for (int i = GOMP_DIM_GANG; i < GOMP_DIM_MAX; i++)
+	if (loop_dim_mask & GOMP_DIM_MASK (i))
+	  loop_dim_mask =
+	    lower_oacc_loop_helper (clauses, ilist, &oacc_gang_reduction_init,
+				    ctx, IFN_GOACC_REDUCTION_SETUP,
+				    IFN_GOACC_REDUCTION_INIT,
+				    IFN_GOACC_FORK, i, loop_dim_mask,
+				    enter_loop);
     }
   else
     {
-      fork_join = IFN_GOACC_JOIN;
-      f1 = IFN_GOACC_REDUCTION_FINI;
-      f2 = IFN_GOACC_REDUCTION_TEARDOWN;
-      seq = &oacc_gang_reduction_fini;
-      dir = -1;
-    }
-
-  for (int i = GOMP_DIM_GANG; i < GOMP_DIM_MAX; i++)
-    {
-      int dim = dir > 0 ? i : GOMP_DIM_MAX - (i + 1);
-      if (loop_dim_mask & GOMP_DIM_MASK (dim))
-	loop_dim_mask =
-	  lower_oacc_loop_helper (clauses, ilist, seq, ctx, f1, f2,
-				  fork_join, dim, loop_dim_mask,
-				  enter_loop);
+      for (int i = GOMP_DIM_MAX; i-- != GOMP_DIM_GANG;)
+	if (loop_dim_mask & GOMP_DIM_MASK (i))
+	  loop_dim_mask =
+	    lower_oacc_loop_helper (clauses, ilist, &oacc_gang_reduction_fini,
+				    ctx, IFN_GOACC_REDUCTION_FINI,
+				    IFN_GOACC_REDUCTION_TEARDOWN,
+				    IFN_GOACC_JOIN, i, loop_dim_mask,
+				    enter_loop);
     }
 }
 

Reply via email to