Question about the loop vectorizer

Hi all,

I have a question about the loop vectorizer.

For the following code:

void example1 (float a, float b, float c, int n) {
    int i;
    for (i=0; i<n; i++){
        a[i] = c[i];
    }
    for (i=0; i<n; i++){
        a[i] += b[i];
    }
}

void example2 (float a, float b, float c, int n) {
    int i;
    for (i=0; i<n; i++){
        a[i] = b[i] + c[i];
    }
}

The two functions are doing the same thing. But only example1 is
vectorized. Is there a reason for not vectorizing example2? Or, is
it simply a feature not available in llvm3.2?

Regards,
Siu

Hi Michael,

Thanks for trying the Loop Vectorizer. All of the loops in the examples you sent are vectorized in LLVM ToT. On Sanybridge, example2 is vectorized to 8 x float (YMM registers) and is unrolled twice. I imagine that 3.2 is too old.

Thanks,
Nadav