[llvm-bugs] [Bug 46070] New: The vectorization of the inner loop stops when "# pragma omp parallel for" is written on the outer loop.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 25 23:49:05 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46070

            Bug ID: 46070
           Summary: The vectorization of the inner loop stops when "#
                    pragma omp parallel for" is written on the outer loop.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: fj8765ah at aa.jp.fujitsu.com
                CC: llvm-bugs at lists.llvm.org

If you write "# pragma omp parallel for" on the outer loop, the vectorization
of the inner loop stops.
If you don't add -fopenmp, vectorization will work.
It is the same with -O3.
Is this a case where vectorization is not possible?

For your information, gcc (Version 9.2.0) will work with vectorization if you
add -fopenmp and -O3.


ng.c:

#define SIZE 1000
float a[SIZE][SIZE],b[SIZE][SIZE],c[SIZE][SIZE];

void sub(int n) {
  int i,j;

#pragma omp parallel for
  for (j=0;j<n;++j) {

    for (i=0;i<n;++i) {
      c[j][i] = a[j][i] + b[j][i];
    }
  }
}

$ clang -S -O2 ng.c -Rpass=vector -Rpass-analysis=vector
ng.c:10:5: remark: vectorized loop (vectorization width: 4, interleaved count:
2) [-Rpass=loop-vectorize]
    for (i=0;i<n;++i) {
    ^
$ clang -S -O2 ng.c -Rpass=vector -Rpass-analysis=vector -fopenmp
ng.c:10:5: remark: loop not vectorized: could not determine number of loop
iterations [-Rpass-analysis=loop-vectorize]
    for (i=0;i<n;++i) {
    ^
$

$ gcc-9.2.0 -O2 ng.c -fopenmp -fopt-info -Wall -S $ gcc-9.2.0 -O3 ng.c -fopenmp
-fopt-info -Wall -S
ng.c:10:5: optimized: loop vectorized using 16 byte vectors
ng.c:10:5: optimized: loop with 2 iterations completely unrolled (header
execution count 64530389) $



ok.c:

#define SIZE 1000
float a[SIZE][SIZE],b[SIZE][SIZE],c[SIZE][SIZE];

void sub(int n) {
  int i,j;

#pragma omp parallel for
  for (j=0;j<SIZE;++j) {

    for (i=0;i<SIZE;++i) {
      c[j][i] = a[j][i] + b[j][i];
    }
  }
}



$ clang -S -O2 ok.c -Rpass=vector -Rpass-analysis=vector
ok.c:10:5: remark: vectorized loop (vectorization width: 4, interleaved count:
2) [-Rpass=loop-vectorize]
    for (i=0;i<SIZE;++i) {
    ^
$ clang -S -O2 ok.c -Rpass=vector -Rpass-analysis=vector -fopenmp
ok.c:10:5: remark: vectorized loop (vectorization width: 4, interleaved count:
2) [-Rpass=loop-vectorize]
    for (i=0;i<SIZE;++i) {
    ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200526/275a15ab/attachment.html>


More information about the llvm-bugs mailing list