I'm trying to vectorize a simple C code. My problem is that I don't quite understand the relationship between clang --target option and the cores mentioned in X86.td as well as other X86 related options (such as -mtune). Below are the command and the code that I'm trying to vectorize. The code compiles but I don't see any vectors. What am I doing wrong? Any help is appreciated. clang -S x.c --target=x86_64-pc-gnu -mtune=core-avx2 -o x.x86.s -fvectorize -fno-lax-vector-conversions -fslp-vectorize-aggressive -fslp-vectorize #define N 32 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; } -- Rail Shafigulin Software Engineer Esencia Technologies -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160316/4d51517c/attachment.html>
You need to enable an optimization level, this vectorizes for me: clang -S x.c --target=x86_64-pc-gnu -mtune=core-avx2 -O3 -S -o - -- Mehdi> On Mar 16, 2016, at 2:29 PM, Rail Shafigulin via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > I'm trying to vectorize a simple C code. My problem is that I don't quite understand the relationship between clang --target option and the cores mentioned in X86.td as well as other X86 related options (such as -mtune). Below are the command and the code that I'm trying to vectorize. The code compiles but I don't see any vectors. What am I doing wrong? Any help is appreciated. > > clang -S x.c --target=x86_64-pc-gnu -mtune=core-avx2 -o x.x86.s -fvectorize -fno-lax-vector-conversions -fslp-vectorize-aggressive -fslp-vectorize > > #define N 32 > > 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; > } > > > > -- > Rail Shafigulin > Software Engineer > Esencia Technologies > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
On Wed, Mar 16, 2016 at 2:34 PM, Mehdi Amini <mehdi.amini at apple.com> wrote:> You need to enable an optimization level, this vectorizes for me: > > clang -S x.c --target=x86_64-pc-gnu -mtune=core-avx2 -O3 -S -o - > > -- > MehdiThanks. It worked! -- Rail Shafigulin Software Engineer Esencia Technologies -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160316/6caa82c2/attachment.html>
Régis Portalez via llvm-dev
2016-Mar-16 23:08 UTC
[llvm-dev] [cfe-dev] vectorization for X86
Hi. I don't know how llvm works internally, but I guess the code you wrote don't need any vectorization. It's probably because its completely memory bound and hardware prefetch will do the job for you. You can force vectorization using some pragmas (I don't remember which). Regis Altimesh -----Message d'origine----- De : "Rail Shafigulin via cfe-dev" <cfe-dev at lists.llvm.org> Envoyé : 16/03/2016 23:00 À : "llvm-dev" <llvm-dev at lists.llvm.org>; "cfe-dev at lists.llvm.org" <cfe-dev at lists.llvm.org> Objet : [cfe-dev] vectorization for X86 I'm trying to vectorize a simple C code. My problem is that I don't quite understand the relationship between clang --target option and the cores mentioned in X86.td as well as other X86 related options (such as -mtune). Below are the command and the code that I'm trying to vectorize. The code compiles but I don't see any vectors. What am I doing wrong? Any help is appreciated. clang -S x.c --target=x86_64-pc-gnu -mtune=core-avx2 -o x.x86.s -fvectorize -fno-lax-vector-conversions -fslp-vectorize-aggressive -fslp-vectorize #define N 32 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; } -- Rail Shafigulin Software Engineer Esencia Technologies -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160317/155a3791/attachment.html>