State of Loop Unrolling and Vectorization in LLVM

Hi , I have a test case (and a micro benchmark made out of the test case) to check if loop unrolling and loop vectorization is efficiently done on LLVM. Here is the test case (credits: Tyler Nowicki)

{code}

extern float * array;

extern int array_size;

float g()

{

int i;

float total = 0;

for(i = 0; i < array_size; i++)

{

total += array[i];

}

return total;

}

{code}

When compiled with the options -m32 -mfpmath=sse -ffast-math -funroll-loops -O3 -march=atom for gcc, and clang, I am not able to see the loop being unrolled / vectorized. The microbenchmark which runs the function g() over a billion times shows quite some performance difference on gcc against clang

Gcc – 8.6 seconds

Clang – 12.7 seconds

Evidently, the addition operation can be vectorized to use addps, (clang does addss), and the loop can be unrolled for better performance. Any idea why this is happening ?

Thanks

Sriram

I take it back.

The trunk version of LLVM does vectorize the loop. As a result, the microbenchmark also runs quite faster when compiled with clang.