<div dir="ltr">Right, and if you are not running it on the target, it's also not going to detect the target features right, i believe?<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 12:46 PM, Michael Kuperstein <span dir="ltr"><<a href="mailto:mkuper@google.com" target="_blank">mkuper@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The loop vectorizer is not independent of the target, since it queries the target for cost estimates to make the vectorization profitability decision. <div><br></div><div>Your code has a pragma explicitly requesting vectorization, so profitability should not come into play, but there may be other target-related issues. One example I can think of is that we will never vectorize if the target has no vector registers.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 12:20 PM, Xiaochu Liu via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">I'm not compiling it to x86. Should loop optimizer something independent of the target? If so, should the vectorized code on IR level? </p><div><div>
<div class="gmail_extra"><br><div class="gmail_quote">On Aug 12, 2016 11:39 AM, "Daniel Berlin" <<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>cat > test.c</div><div><br></div><div>#define SIZE 128</div><div><br></div><div>void bar(int *restrict A, int* restrict B,int K) {</div><div><br></div><div> #pragma clang loop vectorize(enable) vectorize_width(2) unroll_count(8)</div><div><br></div><div> for (int i = 0; i < SIZE; ++i)</div><div><br></div><div> A[i] += B[i] + K;</div><div><br></div><div>}</div><div><br></div><div>[dannyb@dannyb-macbookpro3 11:37:20] ~ :) $ clang -O3 test.c -c -save-temps<br></div><div><div>[dannyb@dannyb-macbookpro3 11:38:28] ~ :) $ pcregrep -i "^\s*p" test.s|less</div><div> pushq %rbp<br></div><div> pshufd $68, %xmm0, %xmm0 ## xmm0 = xmm0[0,1,0,1]</div><div> pslldq $8, %xmm1 ## xmm1 = zero,zero,zero,zero,zero,zero,<wbr>zero,zero,xmm1[0,1,2,3,4,5,6,7<wbr>]</div><div> pshufd $68, %xmm3, %xmm3 ## xmm3 = xmm3[0,1,0,1]</div><div> paddq %xmm1, %xmm3</div><div> pshufd $78, %xmm3, %xmm4 ## xmm4 = xmm3[2,3,0,1]</div><div> punpckldq %xmm5, %xmm4 ## xmm4 = xmm4[0],xmm5[0],xmm4[1],xmm5[1<wbr>]</div><div> pshufd $212, %xmm4, %xmm4 ## xmm4 = xmm4[0,1,1,3]</div></div><div><br></div><div><br></div><div><br></div><div>Note:</div><div>It also vectorizes at SIZE=8.</div><div><br></div><div>Not sure what the exact translation of options from clang-cl to clang is.</div><div>Maybe try adding /O3?<br><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 11:23 AM, Xiaochu Liu <span dir="ltr"><<a href="mailto:xiaochu1122@gmail.com" target="_blank">xiaochu1122@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hi Daniel,</p>
<p dir="ltr">I increased the size of your test to be 128 but -stats still shows no loop optimized...</p><span><font color="#888888">
<p dir="ltr">Xiaochu<br>
</p></font></span><div><div>
<div class="gmail_extra"><br><div class="gmail_quote">On Aug 12, 2016 11:11 AM, "Daniel Berlin" <<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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.<div><br><div><br></div><div>try</div><div><p dir="ltr" style="font-size:12.8px">#define SIZE 8</p><p dir="ltr" style="font-size:12.8px">void bar(int *restrict A, int* restrict B,int K) {</p><p dir="ltr" style="font-size:12.8px"> #pragma clang loop vectorize(enable) vectorize_width(2) unroll_count(8)</p><p dir="ltr" style="font-size:12.8px"> for (int i = 0; i < SIZE; ++i)</p><p dir="ltr" style="font-size:12.8px"> A[i] += B[i] + K;</p><p dir="ltr" style="font-size:12.8px">}</p></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">(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)</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 11:08 AM, Xiaochu Liu via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hi Andrey,</p>
<p dir="ltr">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?</p>
<p dir="ltr">Test:</p>
<p dir="ltr">#define SIZE 8</p>
<p dir="ltr">void bar(int *A, int* B,int K) {</p>
<p dir="ltr"> #pragma clang loop vectorize(enable) vectorize_width(2) unroll_count(8)</p>
<p dir="ltr"> for (int i = 0; i < SIZE; ++i)</p>
<p dir="ltr"> A[i] += B[i] + K;</p>
<p dir="ltr">}</p>
<p dir="ltr">Thanks,<br>
Xiaochu</p><div><div>
<div class="gmail_extra"><br><div class="gmail_quote">On Aug 12, 2016 4:06 AM, "Andrey Bokhanko" <<a href="mailto:andreybokhanko@gmail.com" target="_blank">andreybokhanko@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi <span style="font-size:12.8px">Xiaochu,</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Clang uses -O0 by default, that doesn't run any optimizations. Try supplying -O1 or higher.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Yours,</span></div><div><span style="font-size:12.8px">Andrey</span></div><div><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 1:04 AM, Xiaochu Liu via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hi there ,</p>
<p dir="ltr">I use clang-cl /Qvec test.c to compile the code. But the pass LoopVectorizer is never invoked. </p>
<p dir="ltr">I was wondering if this is sufficient to enable auto vectorizer? </p>
<p dir="ltr">Thanks,<br>
Xiaochu</p>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div></div>
</div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div></div>
</div></div></blockquote></div><br></div>
</blockquote></div></div>
</div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>