On Mon, Mar 17, 2014 at 12:01:54PM +0100, Marek Polacek wrote:
> This patch ensures that we properly expand gomp SIMD builtins even with
> -fno-tree-loop-optimize.  The problem was that we didn't run the 
> loop vectorization at all.  -fno-tree-loop-vectorize already contains
> similar hack.
> 
> Regtested/bootstrapped on x86_64-linux, ok for trunk (or for 5.0?)?
> 
> 2014-03-17  Marek Polacek  <pola...@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..fdf3367 100644
> --- gcc/omp-low.c
> +++ gcc/omp-low.c
> @@ -2931,7 +2931,8 @@ omp_max_vf (void)
>        || optimize_debug
>        || (!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)))

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

> @@ -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.

        Jakub

Reply via email to