When I compile this simple word-wise XOR example, Clang 3.4 does not vectorise it. Why? It seems simpler than the examples in http://llvm.org/docs/Vectorizers.html#features and we do not have data-dependency between single words. So in theory, this can be vectorised.
#include <stdio.h>
void do_xor(const unsigned int num1[5], const unsigned int num2[5]) {
unsigned int num3[5];
// word-wise xor
for (int i = 0; i < 5; ++i)
num3[i] = num1[i] ^ num2[i];
for (int i = 4; i >= 0; --i)
printf("%08x", num3[i]);
printf("\n");
}
using clang -O3 -fslp-vectorize-aggressive -emit-llvm .....
(forcing vectorisation) we end up with (stripped non-function parts):
define void @do_xor(i32* nocapture readonly %num1, i32* nocapture readonly %num2) #0 {
.preheader4:
%0 = load i32* %num1, align 4, !tbaa !1
%1 = load i32* %num2, align 4, !tbaa !1
%2 = xor i32 %1, %0
%3 = getelementptr inbounds i32* %num1, i64 1
%4 = load i32* %3, align 4, !tbaa !1
%5 = getelementptr inbounds i32* %num2, i64 1
%6 = load i32* %5, align 4, !tbaa !1
%7 = xor i32 %6, %4
%8 = getelementptr inbounds i32* %num1, i64 2
%9 = load i32* %8, align 4, !tbaa !1
%10 = getelementptr inbounds i32* %num2, i64 2
%11 = load i32* %10, align 4, !tbaa !1
%12 = xor i32 %11, %9
%13 = getelementptr inbounds i32* %num1, i64 3
%14 = load i32* %13, align 4, !tbaa !1
%15 = getelementptr inbounds i32* %num2, i64 3
%16 = load i32* %15, align 4, !tbaa !1
%17 = xor i32 %16, %14
%18 = getelementptr inbounds i32* %num1, i64 4
%19 = load i32* %18, align 4, !tbaa !1
%20 = getelementptr inbounds i32* %num2, i64 4
%21 = load i32* %20, align 4, !tbaa !1
%22 = xor i32 %21, %19
%23 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i32 %22) #2
%24 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i32 %17) #2
%25 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i32 %12) #2
%26 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i32 %7) #2
%27 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i32 %2) #2
%putchar = tail call i32 @putchar(i32 10) #2
ret void
}
No vector-code generated. Why?