Packed instructions generaetd by LoopVectorize?


I have a question about LoopVectorize. I wrote a simple test case, a dot product loop and found that packed instructions are generated when input arrays are integer, but not when they are float or double.

If I modify the float example in by adding restrict to the input arrays packed instructions are generated. Although it should not be required I tried doing the same to the input arrays of my dot product example but it still doesn’t generate packed float or double instructions.

Is the loop vectorizer supposed to generate packed float and double instructions? Is this a bug, or am I doing something wrong?


float dotproduct(float *A, float *B, int n) {

float sum = 0;

for(int i = 0; i < n; ++i) {

sum += A[i] * B[i];


return sum;


clang dotproduct.cpp -O3 -fvectorize -march=atom -S -o -


movss (%rdi), %xmm1

addq $4, %rdi

mulss (%rsi), %xmm1

addq $4, %rsi

decl %edx

addss %xmm1, %xmm0

jne .LBB1_1

Hi Tyler,

Try adding -ffast-math. We can only vectorize reduction variables if it is safe to reorder floating point operations.


Thanks, that did it!

Are there any plans to enable the loop vectorizer by default?

Its already enabled by default for -O3. The plan is to enable it by default for -Os and -O2 for the LLVM 3.4 release, but we know that this requires some work.