<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - clang loop vectorizer doesn't work when reduction variable is a slot in an array"
   href="https://llvm.org/bugs/show_bug.cgi?id=27625">27625</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang loop vectorizer doesn't work when reduction variable is a slot in an array
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.8
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>albertnetymk@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>```
#define SIZE (1 << 15)

#define XMM_ALIGNMENT_BYTES 16

float *vec_a __attribute__((aligned (XMM_ALIGNMENT_BYTES)));
float *vec_b __attribute__((aligned (XMM_ALIGNMENT_BYTES)));
float *vec_c __attribute__((aligned (XMM_ALIGNMENT_BYTES)));

void matvec_autovec()
{
    int i, j;

    for (i = 0; i < SIZE; i++) {
        for (j = 0; j < SIZE; j++) {
            vec_c[i] += vec_a[j] * vec_b[j];
        }
    }
}
```

Command used: `clang-3.8 -c -S -Ofast -Rpass-analysis=loop-vectorize test.c`

```
test.c:17:22: remark: loop not vectorized: value that could not be identified
as reduction is used outside the loop [-Rpass-analysis=loop-vectorize]
            vec_c[i] += vec_a[j] * vec_b[j];```
```

I was expecting that `vec_c[i]` to be treated as inner loop invariant and the
vectorization would work. The auto-vectorization works fine if I use a tmp
variable for accumulation. Could someone explain why the vectorizer bails out
in this case?</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>