Skip to content

clang loop vectorizer doesn't work when reduction variable is pointer type #27999

@llvmbot

Description

@llvmbot
Bugzilla Link 27625
Version 3.8
OS Linux
Reporter LLVM Bugzilla Contributor
CC @hfinkel

Extended Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions