This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/46032] openmp inhibits loop vectorization


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46032

--- Comment #21 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to vries from comment #20)
> This patch seems to have the desired effect on the original testcase: 
> ...
> diff --git a/gcc/omp-low.c b/gcc/omp-low.c
> index 830db75..996756b 100644
> --- a/gcc/omp-low.c
> +++ b/gcc/omp-low.c
> @@ -9361,6 +9361,7 @@ expand_omp_for_static_nochunk (struct omp_region
> *region,
>        if (collapse_bb == NULL)
>         loop->latch = cont_bb;
>        add_loop (loop, body_bb->loop_father);
> +      loop->safelen = INT_MAX;
>      }
>  }
> ...
> 
> AFAIU, adding the omp for to the loop is an assertion that the loop is
> independent. It seems reasonable to assume that if the original loop was
> independent, the loop operating on a slice of the original iteration space
> will be independent as well.

That is very much wrong.  Static scheduling, both nochunk and chunk, doesn't
imply in any way that the iterations are independent, the OpenMP standard says
how the work is split among the threads, with nochunk that threads get
consecutive sets of iterations as one chunk that are approximately the same
size, but eventhough it is not exactly specified how exactly the iteration
space is deviced (for nochunk), if you make the loop iterations independent,
you would break many observable properties (say through threadprivate vars,
omp_get_thread_num etc.).
Note loop->safelen == INT_MAX is actually weaker than independent iterations,
when loop->safelen == INT_MAX, there can be dependencies, but only of certain
kinds, it says that it is equivalent if you run the loop normally and if you
run simultaneously (or emulated) the first statements of all the iterations,
then second statements and so on (so vectorize with any vectorization factor
the compiler wants).

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]