<div dir="ltr">when i change it to following: then get error: remark: <unknown>:0:0: loop not vectorized: call instruction cannot be vectorized<div><div>int main(int argc, char** argv) {</div><div>int a[1000], b[1000], c[1000]; int g=0;</div><div>for (int i=0; i<1000; i++) {<br></div><div>a[i]=atoi(argv[1]), b[i]=atoi(argv[2]);</div><div> c[i]=a[i] + b[i];</div><div>g+=c[i];<br></div><div>}</div></div><div><br></div><div>Here my main goal is that <span style="font-size:12.8px">i need to use JIT to perform operations on user input file supplied at run time using vector instructions. is it possible and achievable through JIT?</span></div><div>Please help.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 11:44 PM, Craig Topper <span dir="ltr"><<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.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">I assume compiler knows that your only have 2 input values that you just added together 1000 times.<div><br></div><div>Despite the fact that you stored to a[i] and b[i] here, nothing reads them other than the addition in the same loop iteration. So the compiler easily removed the a and b arrays. Same with 'c', it's not read outside the loop so it doesn't need to exist. So the compiler turned your loop body back into g+= aa + bb; And since the loop is 1000 iterations and aa and bb never change this got further simplified to (aa+bb)*1000.</div><span class=""><div><br></div><div><span style="font-size:12.8px">int main(int argc, char** argv) {</span><div style="font-size:12.8px">int a[1000], b[1000], c[1000]; int g=0;</div><span style="font-size:12.8px"><div>int aa=atoi(argv[1]), bb=atoi(argv[2]);</div><div>for (int i=0; i<1000; i++) {</div><div>a[i]=aa, b[i]=bb;</div><div> c[i]=a[i] + b[i];</div></span><div style="font-size:12.8px">g+=c[i];<br></div><div style="font-size:12.8px">}</div></div></span></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_-7474266683858256224gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Thu, Aug 17, 2017 at 11:37 AM, hameeza ahmed <span dir="ltr"><<a href="mailto:hahmed2305@gmail.com" target="_blank">hahmed2305@gmail.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">why is it happening? is there any way to solve this?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 10:09 PM, hameeza ahmed <span dir="ltr"><<a href="mailto:hahmed2305@gmail.com" target="_blank">hahmed2305@gmail.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">even if i make my code as follows: vectorized instructions not get emitted. What to do?<div><br><div><span><div>int main(int argc, char** argv) {</div></span><div>int a[1000], b[1000], c[1000]; int g=0;</div><span><div>int aa=atoi(argv[1]), bb=atoi(argv[2]);</div><div>for (int i=0; i<1000; i++) {</div><div>a[i]=aa, b[i]=bb;</div><div> c[i]=a[i] + b[i];</div></span><div>g+=c[i];<br></div><div>}</div><div><br></div><div>printf("sum: %d\n", g);</div><div><br></div><div>return 0;</div><div>}</div></div></div></div><div class="m_-7474266683858256224m_8769496259533141939HOEnZb"><div class="m_-7474266683858256224m_8769496259533141939h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 10:03 PM, Craig Topper <span dir="ltr"><<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.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">Did you remove the printf completely? Meaning that nothing accesses 'c' after the loop? If so it got removed as dead code because it had no visible effect.</div><div class="gmail_extra"><span class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594h5">
<br><div class="gmail_quote">On Thu, Aug 17, 2017 at 10:01 AM, hameeza ahmed <span dir="ltr"><<a href="mailto:hahmed2305@gmail.com" target="_blank">hahmed2305@gmail.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">i removed printf from loop. Now getting no error. but the IR doesnot contain vectorized code. IR Output is as follows:<div><div>; ModuleID = 'sum-vec.ll'</div><div>source_filename = "sum-vec.c"</div><div>target datalayout = "e-m:e-i64:64-f80:128-n8:16:32<wbr>:64-S128"</div><div>target triple = "x86_64-unknown-linux-gnu"</div><div><br></div><div>; Function Attrs: norecurse nounwind readnone uwtable</div><div>define i32 @main(i32, i8** nocapture readnone) local_unnamed_addr #0 {</div><div>  ret i32 0</div><div>}</div><div><br></div><div>attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt<wbr>-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false<wbr>" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="fal<wbr>se" "no-trapping-math"="false" "stack-protector-buffer-size"=<wbr>"8" "target-cpu"="knl" "target-features"="+adx,+aes,+<wbr>avx,+avx2,+avx512cd,+avx512er,<wbr>+avx512f,+avx512pf,+bmi,+bmi2,<wbr>+cx16,+f16c,+fma,+fsgsbase,+fx<wbr>sr,+lzcnt,+mmx,+movbe,+pclmul,<wbr>+popcnt,+prefetchwt1,+rdrnd,+r<wbr>dseed,+rtm,+sse,+sse2,+sse3,+s<wbr>se4.1,+sse4.2,+ssse3,+x87,+xsa<wbr>ve,+xsaveopt" "unsafe-fp-math"="false" "use-soft-float"="false" }</div><div><br></div><div>!llvm.ident = !{!0}</div><div><br></div><div>!0 = !{!"clang version 4.0.0 (tags/RELEASE_400/final)"}</div></div><div><br></div><div>what to do? please help.</div><div><br></div></div><div class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186HOEnZb"><div class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 9:57 PM, Nemanja Ivanovic <span dir="ltr"><<a href="mailto:nemanja.i.ibm@gmail.com" target="_blank">nemanja.i.ibm@gmail.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">Move the printf out of the loop and it should vectorize just fine.<br></div><div class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186m_-8326072891700327931HOEnZb"><div class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186m_-8326072891700327931h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 6:52 PM, hameeza ahmed <span dir="ltr"><<a href="mailto:hahmed2305@gmail.com" target="_blank">hahmed2305@gmail.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">I want to vectorize the user given inputs. when opt does vectorization user supplied inputs (from a text file) will be added using AVX vector instructions.<div><br></div><div>as you pointed; When i changed my code to following:</div><div><br></div><div><div>int main(int argc, char** argv) {</div><div>int a[1000], b[1000], c[1000];</div><div>int aa=atoi(argv[1]), bb=atoi(argv[2]);</div><div>for (int i=0; i<1000; i++) {</div><div>a[i]=aa, b[i]=bb;</div><div> c[i]=a[i] + b[i];</div><div>printf("sum: %d\n", c[i]);</div><div><br></div><div>}</div></div><div><br></div><div>I am getting error remark: <unknown>:0:0: loop not vectorized: call instruction cannot be vectorized.</div><div><br></div><div>I am running following commands:</div><div>clang  -S -emit-llvm sum-vec.c -march=knl -O3 -mllvm -disable-llvm-optzns -o sum-vec.ll<br></div><div>opt  -S -O3 -force-vector-width=64 sum-vec.ll -o sum-vec03.ll<br></div><div><br></div><div>How to achieve this? Please help.</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 10:44 AM, Nemanja Ivanovic <span dir="ltr"><<a href="mailto:nemanja.i.ibm@gmail.com" target="_blank">nemanja.i.ibm@gmail.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">I'm not sure what you expect to have vectorized here. If you look at the emitted code, there's no loop. It's just an add and a multiply as you might expect when adding a loop-invariant sum 1000 times in a loop.<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186m_-8326072891700327931m_-9083316128729032069m_-5426776120835238504h5">On Wed, Aug 16, 2017 at 11:38 PM, hameeza ahmed 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></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186m_-8326072891700327931m_-9083316128729032069m_-5426776120835238504h5"><div dir="ltr">Hello, <div>I have written the following code. when i try to vectorize it through opt. i am not getting vectorized instructions.</div><div><br></div><div><div>#include <stdio.h></div><div>#include<stdlib.h></div><div>int main(int argc, char** argv) {</div><div>int sum=0; int a=atoi(argv[1]); int b=atoi(argv[2]);</div><div>for (int i=0;i<1000;i++)</div><div>{</div><div>sum+=a+b;<br></div><div>}</div><div><br></div><div>printf("sum: %d\n", sum);</div><div>return 0;</div><div>}</div></div><div>i use following commands:</div><div><div>clang  -S -emit-llvm sum-main.c -march=knl -O3 -mllvm -disable-llvm-optzns -o sum-main.ll</div></div><div><div>opt  -S -O3 -force-vector-width=64 sum-main.ll -o sum-main03.ll</div></div><div><br></div><div>why is that so? where am i doing mistake? i am not getting vectorized operations rather getting scalar operations.</div><div><br></div><div>Please help.</div><div><br></div><div>Thank You</div><div><br></div><div>Regards</div><div><br></div></div>
<br></div></div>______________________________<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><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div>