Hi Andrey, Thanks. I found even when loop vectorizer and SLP vectorizer are enabled, my simple test still not get optimized. I also tried clang pragma in my test to force vectorization. What do you think is the problem? Test: #define SIZE 8 void bar(int *A, int* B,int K) { #pragma clang loop vectorize(enable) vectorize_width(2) unroll_count(8) for (int i = 0; i < SIZE; ++i) A[i] += B[i] + K; } Thanks, Xiaochu On Aug 12, 2016 4:06 AM, "Andrey Bokhanko" <andreybokhanko at gmail.com> wrote:> Hi Xiaochu, > > Clang uses -O0 by default, that doesn't run any optimizations. Try > supplying -O1 or higher. > > Yours, > Andrey > > > On Fri, Aug 12, 2016 at 1:04 AM, Xiaochu Liu via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hi there , >> >> I use clang-cl /Qvec test.c to compile the code. But the pass >> LoopVectorizer is never invoked. >> >> I was wondering if this is sufficient to enable auto vectorizer? >> >> Thanks, >> Xiaochu >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160812/84449f23/attachment.html>
It's not possible to know that A and B don't alias in this example. It's almost certainly not profitable to add a runtime check given the size of the loop. try #define SIZE 8 void bar(int *restrict A, int* restrict B,int K) { #pragma clang loop vectorize(enable) vectorize_width(2) unroll_count(8) for (int i = 0; i < SIZE; ++i) A[i] += B[i] + K; } (i don't remember if llvm also does runtime alias checks, but if it does, you'd probably need to increase size to get it to vectorize) On Fri, Aug 12, 2016 at 11:08 AM, Xiaochu Liu via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi Andrey, > > Thanks. I found even when loop vectorizer and SLP vectorizer are enabled, > my simple test still not get optimized. I also tried clang pragma in my > test to force vectorization. What do you think is the problem? > > Test: > > #define SIZE 8 > > void bar(int *A, int* B,int K) { > > #pragma clang loop vectorize(enable) vectorize_width(2) unroll_count(8) > > for (int i = 0; i < SIZE; ++i) > > A[i] += B[i] + K; > > } > > Thanks, > Xiaochu > > On Aug 12, 2016 4:06 AM, "Andrey Bokhanko" <andreybokhanko at gmail.com> > wrote: > >> Hi Xiaochu, >> >> Clang uses -O0 by default, that doesn't run any optimizations. Try >> supplying -O1 or higher. >> >> Yours, >> Andrey >> >> >> On Fri, Aug 12, 2016 at 1:04 AM, Xiaochu Liu via llvm-dev < >> llvm-dev at lists.llvm.org> wrote: >> >>> Hi there , >>> >>> I use clang-cl /Qvec test.c to compile the code. But the pass >>> LoopVectorizer is never invoked. >>> >>> I was wondering if this is sufficient to enable auto vectorizer? >>> >>> Thanks, >>> Xiaochu >>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> llvm-dev at lists.llvm.org >>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >>> >>> >> > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160812/1d9ab5c7/attachment.html>
Hi Daniel, I increased the size of your test to be 128 but -stats still shows no loop optimized... Xiaochu On Aug 12, 2016 11:11 AM, "Daniel Berlin" <dberlin at dberlin.org> wrote:> It's not possible to know that A and B don't alias in this example. It's > almost certainly not profitable to add a runtime check given the size of > the loop. > > > try > > #define SIZE 8 > > void bar(int *restrict A, int* restrict B,int K) { > > #pragma clang loop vectorize(enable) vectorize_width(2) unroll_count(8) > > for (int i = 0; i < SIZE; ++i) > > A[i] += B[i] + K; > > } > > (i don't remember if llvm also does runtime alias checks, but if it does, > you'd probably need to increase size to get it to vectorize) > > On Fri, Aug 12, 2016 at 11:08 AM, Xiaochu Liu via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hi Andrey, >> >> Thanks. I found even when loop vectorizer and SLP vectorizer are enabled, >> my simple test still not get optimized. I also tried clang pragma in my >> test to force vectorization. What do you think is the problem? >> >> Test: >> >> #define SIZE 8 >> >> void bar(int *A, int* B,int K) { >> >> #pragma clang loop vectorize(enable) vectorize_width(2) unroll_count(8) >> >> for (int i = 0; i < SIZE; ++i) >> >> A[i] += B[i] + K; >> >> } >> >> Thanks, >> Xiaochu >> >> On Aug 12, 2016 4:06 AM, "Andrey Bokhanko" <andreybokhanko at gmail.com> >> wrote: >> >>> Hi Xiaochu, >>> >>> Clang uses -O0 by default, that doesn't run any optimizations. Try >>> supplying -O1 or higher. >>> >>> Yours, >>> Andrey >>> >>> >>> On Fri, Aug 12, 2016 at 1:04 AM, Xiaochu Liu via llvm-dev < >>> llvm-dev at lists.llvm.org> wrote: >>> >>>> Hi there , >>>> >>>> I use clang-cl /Qvec test.c to compile the code. But the pass >>>> LoopVectorizer is never invoked. >>>> >>>> I was wondering if this is sufficient to enable auto vectorizer? >>>> >>>> Thanks, >>>> Xiaochu >>>> >>>> _______________________________________________ >>>> LLVM Developers mailing list >>>> llvm-dev at lists.llvm.org >>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >>>> >>>> >>> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160812/d555cb15/attachment.html>