<div dir="ltr">So your clang command line says -march=knl. Are you using a Xeon Phi to run your code? if not that's why you're failing. Try changing it to -march=native</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote">On Thu, Aug 17, 2017 at 12:21 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"><div>lli sum-vec03.ll  5 2 #0 0x0000000000c1f818 (lli+0xc1f818)</div><div>#1 0x0000000000c1d90e (lli+0xc1d90e)</div><div>#2 0x0000000000c1da5c (lli+0xc1da5c)</div><div>#3 0x00007f987c2c3d10 __restore_rt (/lib/x86_64-linux-gnu/<wbr>libpthread.so.0+0x10d10)</div><div>#4 0x00007f987c6f0038</div><div>#5 0x0000000000989f8c (lli+0x989f8c)</div><div>#6 0x00000000009383dc (lli+0x9383dc)</div><div>#7 0x000000000057eedd (lli+0x57eedd)</div><div>#8 0x00007f987b464a40 __libc_start_main (/lib/x86_64-linux-gnu/libc.<wbr>so.6+0x20a40)</div><div>#9 0x00000000005a5b49 (lli+0x5a5b49)</div><span class=""><div>Stack dump:</div><div>0.<span style="white-space:pre-wrap">  </span>Program arguments: lli sum-vec03.ll 5 2 </div><div>Illegal instruction (core dumped)</div><div><br></div></span><div>No yet there exists no link with those new 2048 element instructions that i discussed earlier. i need to link jit with that later. presently, i am exploring jit in general to know its capabilities. </div><span class=""><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Here my main goal is that </span><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><br></div></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 18, 2017 at 12:17 AM, 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">What was your lli command line? Is this based on your code where you created 2048-bit instructions in the x86 backend?</div><div class="gmail_extra"><span class="m_4699344656396336257HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_4699344656396336257m_-9003893617123899015gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_4699344656396336257h5">
<br><div class="gmail_quote">On Thu, Aug 17, 2017 at 12:12 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">Ok. I have managed to vectorize the second loop in the following code. But the first loop is still not vectorized? Why?<div><br></div><div><span><div>int main(int argc, char** argv) {</div><div>int a[1000], b[1000], c[1000]; int g=0;</div><div>int aa=atoi(argv[1]), bb=atoi(argv[2]);</div><div><br></div><div>for (int i=0; i<1000; i++) {</div></span><div>a[i]=aa+i, b[i]=bb+i;}</div><span><div><br></div><div>for (int i=0; i<1000; i++) {</div></span><span><div> c[i]=a[i] + b[i];</div><div>g+=c[i];</div><div>}</div><div><br></div><div>printf("sum: %d\n", g);</div><div><br></div><div>return 0;</div><div>}</div></span></div><div><br></div><div>When i executed the optimized IR through jit (lli sum-vec03.ll  5 2) i am getting following error:</div><div><br></div><div><div>#0 0x00000000013f965c llvm::sys::PrintStackTrace(llv<wbr>m::raw_ostream&) /lib/Support/Unix/Signals.inc:<wbr>402:11</div><div>#1 0x00000000013f9b49 PrintStackTraceSignalHandler(v<wbr>oid*) /lib/Support/Unix/Signals.inc:<wbr>466:1</div><div>#2 0x00000000013f7ec3 llvm::sys::RunSignalHandlers() /lib/Support/Signals.cpp:0:5</div><div>#3 0x00000000013f9ea4 SignalHandler(int) /lib/Support/Unix/Signals.inc:<wbr>256:1</div><div>#4 0x00007fcdece96d10 __restore_rt (/lib/x86_64-linux-gnu/libpthr<wbr>ead.so.0+0x10d10)</div><div>#5 0x00007fcded2c3038</div><div>#6 0x0000000000f4a8fb llvm::MCJIT::runFunction(llvm:<wbr>:Function*, llvm::ArrayRef<llvm::GenericVa<wbr>lue>) /lib/ExecutionEngine/MCJIT/MCJ<wbr>IT.cpp:538:31</div><div>#7 0x0000000000eaff23 llvm::ExecutionEngine::runFunc<wbr>tionAsMain(llvm::Function*, std::vector<std::__cxx11::basi<wbr>c_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::b<wbr>asic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*) /lib/ExecutionEngine/Execution<wbr>Engine.cpp:471:10</div><div>#8 0x00000000007be4e9 main /tools/lli/lli.cpp:627:18</div><div>#9 0x00007fcdebe2fa40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so<wbr>.6+0x20a40)</div><div>#10 0x00000000007bc169 _start (/bin/lli+0x7bc169)</div><div>Stack dump:</div><div>0.<span style="white-space:pre-wrap">      </span>Program arguments:lli sum-vec03.ll 5 2 </div><div>Illegal instruction (core dumped)</div></div><div><br></div><div><br></div><div>What is wrong here? please help.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="m_4699344656396336257m_-9003893617123899015HOEnZb"><div class="m_4699344656396336257m_-9003893617123899015h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 11:51 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">when i change it to following: then get error: remark: <unknown>:0:0: loop not vectorized: call instruction cannot be vectorized<div><span><div>int main(int argc, char** argv) {</div><div>int a[1000], b[1000], c[1000]; int g=0;</div></span><span><div>for (int i=0; i<1000; i++) {<br></div></span><div>a[i]=atoi(argv[1]), b[i]=atoi(argv[2]);</div><span><div> c[i]=a[i] + b[i];</div><div>g+=c[i];<br></div><div>}</div></span></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="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558HOEnZb"><div class="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558h5"><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><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="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-7474266683858256224gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509h5">
<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_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-7474266683858256224m_8769496259533141939HOEnZb"><div class="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-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_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-7474266683858256224m_8769496259533141939m_8963143490367774594HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-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_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186HOEnZb"><div class="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-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_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-7474266683858256224m_8769496259533141939m_8963143490367774594m_2098162457735726186m_-8326072891700327931HOEnZb"><div class="m_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-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_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-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_4699344656396336257m_-9003893617123899015m_-6746228625338555558m_3226566376735944509m_-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>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>