[PATCH] Expand OpenMP SIMD even with -fno-tree-loop-optimize (PR middle-end/60534)

Marek Polacek polacek@redhat.com
Mon Mar 17 13:52:00 GMT 2014


On Mon, Mar 17, 2014 at 12:16:08PM +0100, Jakub Jelinek wrote:
> No.  IMHO this needs to be:
>         || optimize_debug
> +	|| !flag_no_tree_loop_optimize
>         || (!flag_tree_loop_vectorize
> 	    && (global_options_set.x_flag_tree_loop_vectorize

I presume you mean !flag_tree_loop_optimize.
 
> > @@ -6834,11 +6835,12 @@ expand_omp_simd (struct omp_region *region, struct omp_for_data *fd)
> >  	  loop->simduid = OMP_CLAUSE__SIMDUID__DECL (simduid);
> >  	  cfun->has_simduid_loops = true;
> >  	}
> > -      /* If not -fno-tree-loop-vectorize, hint that we want to vectorize
> > -	 the loop.  */
> > +      /* If not -fno-tree-loop-vectorize of -fno-tree-loop-optimize,
> > +         hint that we want to vectorize the loop.  */
> >        if ((flag_tree_loop_vectorize
> >  	   || (!global_options_set.x_flag_tree_loop_vectorize
> > -               && !global_options_set.x_flag_tree_vectorize))
> > +	       && !global_options_set.x_flag_tree_vectorize
> > +	       && !global_options_set.x_flag_tree_loop_optimize))
> 
> Similarly, here it should be added as
> 
> +	  && flag_tree_loop_optimize
> >  	  && loop->safelen > 1)
> 
> The thing is, if -fno-tree-loop-optimize (whether explicitly added by user
> or implicitly through other options, then the loop will be never vectorized.
> It doesn't matter if -ftree-vectorize was on or not in that case.
> 
> The magic with global_options_set is there to make the loop vectorized
> if either -ftree-loop-vectorize is on (implicitly or explicitly), or
> at least optimizing and not disabled explicitly (-fno-tree-vectorize),
> we then force the vectorization on for the specific loops.
> 
> But -fno-tree-loop-optimize means the whole loop optimization pipeline is
> not performed, at that point forcing it on and disabling all other loop
> optimizations might be too problematic/error prone.
> 
> E.g. you could try -fopenmp -O -fno-tree-loop-optimize -ftree-vectorize
> or -fopenmp -O3 -fno-tree-loop-optimize etc.

:( sorry, fixed.  No ICE with these options.

Regtested on x86_64-linux, ok now?

2014-03-17  Marek Polacek  <polacek@redhat.com>

	PR middle-end/60534
	* omp-low.c (omp_max_vf): Treat -fno-tree-loop-optimize the same
	as -fno-tree-loop-vectorize.
	(expand_omp_simd): Likewise.
testsuite/
	* gcc.dg/gomp/pr60534.c: New test.

diff --git gcc/omp-low.c gcc/omp-low.c
index 91c8656..24ef3c8 100644
--- gcc/omp-low.c
+++ gcc/omp-low.c
@@ -2929,6 +2929,7 @@ omp_max_vf (void)
 {
   if (!optimize
       || optimize_debug
+      || !flag_tree_loop_optimize
       || (!flag_tree_loop_vectorize
 	  && (global_options_set.x_flag_tree_loop_vectorize
               || global_options_set.x_flag_tree_vectorize)))
@@ -6839,6 +6840,7 @@ expand_omp_simd (struct omp_region *region, struct omp_for_data *fd)
       if ((flag_tree_loop_vectorize
 	   || (!global_options_set.x_flag_tree_loop_vectorize
                && !global_options_set.x_flag_tree_vectorize))
+	  && flag_tree_loop_optimize
 	  && loop->safelen > 1)
 	{
 	  loop->force_vect = true;
diff --git gcc/testsuite/gcc.dg/gomp/pr60534.c gcc/testsuite/gcc.dg/gomp/pr60534.c
index e69de29..f8a6bdc 100644
--- gcc/testsuite/gcc.dg/gomp/pr60534.c
+++ gcc/testsuite/gcc.dg/gomp/pr60534.c
@@ -0,0 +1,16 @@
+/* PR middle-end/60534 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -O -fno-tree-loop-optimize" } */
+
+extern int d[];
+
+int
+foo (int a)
+{
+  int c = 0;
+  int l;
+#pragma omp simd reduction(+: c)
+  for (l = 0; l < a; ++l)
+    c += d[l];
+  return c;
+}

	Marek



More information about the Gcc-patches mailing list