<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - The vectorization of the inner loop stops when "# pragma omp parallel for" is written on the outer loop."
   href="https://bugs.llvm.org/show_bug.cgi?id=46070">46070</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>The vectorization of the inner loop stops when "# pragma omp parallel for" is written on the outer loop.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>fj8765ah@aa.jp.fujitsu.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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) {
    ^</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>