[llvm-bugs] [Bug 27625] New: clang loop vectorizer doesn't work when reduction variable is a slot in an array

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 3 14:37:42 PDT 2016


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

            Bug ID: 27625
           Summary: clang loop vectorizer doesn't work when reduction
                    variable is a slot in an array
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: albertnetymk at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

```
#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?

-- 
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/20160503/308b7a58/attachment-0001.html>


More information about the llvm-bugs mailing list