Vectorizing "hybrid" SOA

Do anyone know how to get LLVM’s vectorizer to work on this code?

struct pair {
int x[4], y[4];
};

void foo(int n, struct pair *a, int *restrict rx, int *restrict ry) {
int x = 0, y = 0;
for (int i = 0; i < n; i++) {
x += (a+(i/4))->x[i%4];
y += (a+(i/4))->y[i%4];
}
*rx = x;
*ry = y;
}

I have a pass that converts structures such as {int, int} into {int x 4, int x 4}, but the transformation is profitable if it can work with the vectorizer.

If the loop gets unrolled by 4x I think SLP could cover it.

I guess the loopvectorizer should in theory be able to do this, so you could look into why it isn’t doing it, perhaps by checking the debug log.

—escha