[clang] [llvm] [OpenMP] Diagnostic check for imperfect loop collapse (PR #96087)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 09:48:33 PDT 2024


alexey-bataev wrote:

> > something like
> 
> > 
> 
> > ```
> 
> > bool Init[N] = {false};
> 
> > for (int ij = 0; ij < N*N; ij++) {
> 
> >   int i = ij / N, j = ij % N;
> 
> >   #pragma omp critical
> 
> >   if (!Init[i]) {
> 
> >     arr2[i] = i;
> 
> >     Init[i] = true;
> 
> >   }
> 
> >   arr1[i][j] += arr2[i];
> 
> > }
> 
> > ```
> 
> 
> 
> I don't think synthesizing a critical region inside the collapsed loop will be a win overall, and also I don't quite see how it helps in this case. A correct version would be doing something like serialising the loop, I think, which I suppose sort of bypasses the problem, but doesn't really solve it. (When would we do such a transformation? How much analysis do we need to avoid killing performance in non-contrived cases?)

It should be done in the frontend. And here we should care about correctness, not performance.
Sure, this can be optimized for better performance later in OpenMPOpt pass,  but from the frontend we should get it working correctly.

https://github.com/llvm/llvm-project/pull/96087


More information about the llvm-commits mailing list