My question is:
How do I make clang to generate assembly with vector instruction for my target?
The back story is:
I’ve added a few vector instructions to my target and confirmed that they are used by running my code on the test below and using a following command:
opt i.esencia.ll -S -march=esencia -mcpu=esencia -loop-vectorize | llc -mcpu=esencia -o i.esencia.s
target datalayout = “E-m:e-p:32:32-i64:32-f64:32-v64:32-v128:32-a:0:32-n32”
target triple = “esencia”
; Function Attrs: nounwind uwtable
define i32 @main() {
entry:
%z = alloca <4 x i32>
%a = alloca <4 x i32>
%b = alloca <4 x i32>
%a.l = load <4 x i32>* %a
%b.l = load <4 x i32>* %b
%z.l = add <4 x i32> %a.l, %b.l
store <4 x i32> %z.l, <4 x i32>* %z
ret i32 0
}
Now I’m trying to run clang and vectorize the following test:
#define N 16
int main () {
int a[N], b[N];
int c[N];
for (int i = 0; i < N; ++i)
c[i] = a[i] + b[i];
int sum=0;
for (int i = 0; i < N; ++i)
sum += c[i];
return sum;
}
Here are the command lines I tried:
clang -S test.c --target=esencia -fvectorize -o test.esencia.s
clang -S test.c --target=esencia -fvectorize -fslp-vectorize-aggressive -o test.esencia.s -fslp-vectorize
clang -S test.c --target=esencia -fvectorize -fslp-vectorize-aggressive -o test.esencia.s -fslp-vectorize -fno-lax-vector-conversions
Unfortunately nothing worked. Can someone help me out? I can’t really figure out why this is not working.
Any help is appreciated.