<div><div dir="auto">Making your arrays global will work as well because they're accessible externally and changes to them cannot be optimized out. </div><br><div class="gmail_quote"><div>On Thu, Aug 17, 2017 at 7:11 PM Francois Fayard via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">LLVM is very smart about deleting useless code.<div><br></div><div>If you want to see vectorized code, I would suggest to write such a function.</div><div><br></div><div>int f(int* a, int* b, int n) {</div><div>  int ans = 0;</div><div>  for (int i = 0; i < n; ++i) {</div><div>    ans += a[i] * b[i];</div><div>  }</div><div>  return ans;</div><div>}</div><div><br></div><div>That way, the compiler knows nothing about the values of a and b and cannot optimize anything. Also, beware of pointer aliasing which might prevent vectorization or create 2 different paths : one vectorized, one not vectorized.</div><div><br></div><div><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">François Fayard<br></div></div>
</div></div></div><div style="word-wrap:break-word"><div>
<br><div><blockquote type="cite"><div>On Aug 17, 2017, at 7:01 PM, hameeza ahmed via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="m_-4939260962621598539Apple-interchange-newline"><div><div>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: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-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="knl" "target-features"="+adx,+aes,+avx,+avx2,+avx512cd,+avx512er,+avx512f,+avx512pf,+bmi,+bmi2,+cx16,+f16c,+fma,+fsgsbase,+fxsr,+lzcnt,+mmx,+movbe,+pclmul,+popcnt,+prefetchwt1,+rdrnd,+rdseed,+rtm,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+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="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 9:57 PM, Nemanja Ivanovic <span><<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>Move the printf out of the loop and it should vectorize just fine.<br></div><div class="m_-4939260962621598539HOEnZb"><div class="m_-4939260962621598539h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 6:52 PM, hameeza ahmed <span><<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>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><<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>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_-4939260962621598539m_-9083316128729032069m_-5426776120835238504h5">On Wed, Aug 16, 2017 at 11:38 PM, hameeza ahmed via llvm-dev <span><<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_-4939260962621598539m_-9083316128729032069m_-5426776120835238504h5"><div>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>_______________________________________________<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/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>
_______________________________________________<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" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div></div>_______________________________________________<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/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>