<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 18, 2016, at 2:17 PM, Rail Shafigulin <<a href="mailto:rail@esenciatech.com" class="">rail@esenciatech.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Mar 18, 2016 at 2:03 PM, Rail Shafigulin <span dir="ltr" class=""><<a href="mailto:rail@esenciatech.com" target="_blank" class="">rail@esenciatech.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><span class="">On Fri, Mar 18, 2016 at 1:53 PM, Mehdi Amini <span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Mar 18, 2016, at 1:47 PM, Rail Shafigulin <<a href="mailto:rail@esenciatech.com" target="_blank" class="">rail@esenciatech.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class=""><div class=""><div class=""><span style="color:rgb(34,34,34)" class="">Yes this IR does not build or shuffle any vector. Try to write a function that takes 8 ints and a pointer to a <4xi32>, builds two vectors with the 8 ints,</span></div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">This might sound like a dumb question, but how does one build a vector of ints out of regular ints in IR? </div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">See: <a href="http://llvm.org/docs/LangRef.html#vector-operations" target="_blank" class="">http://llvm.org/docs/LangRef.html#vector-operations</a></div><div class=""><br class=""></div><div class="">In short, the IR has "insertelement", which maps to "INSERT_VECTOR_ELT" in SDAG and "extractelement", which maps to "EXTRACT_VECTOR_ELT" in SDAG.</div><div class=""><br class=""></div><div class="">I usually find good example by grepping in the lit tests. Another way is to write the function in clang, and run it with -O3 -emit-llvm -S to get a good starting point.</div></div></div></blockquote></span><div class="">I tried using clang test.c -O3 -emit-llvm -S, but the only I didn't see any of the insertvectorelt or extractvectorelt. I'm wondering how does one trigger vector operations? </div><div class=""><br class=""></div><div class="">Below is the test.c file. It seemed to me like a good candidate for vectorization, however nothing happened. I would really appreciate  if you could point me in the right<br class=""></div><div class="">direction with respect to vector generation.</div></div></div></div></blockquote></div></div></div></div></blockquote><div><br class=""></div><div>I see vectorization happening on this example (see below).</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">Any help is appreciated.</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><span class=""><font color="#888888" class=""><div class=""><br class=""></div><span class=""><font color="#888888" class=""><div class="">-- </div><div class="">Mehdi</div></font></span></font></span></div></div></blockquote></div><span class=""><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">Rail Shafigulin<br class=""></div>Software Engineer <br class="">Esencia Technologies<br class=""></div></div></div></div>
</span></div></div>
</blockquote></div><br class="">Forgot to attach a C file. Here it is:</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra"><div class="gmail_extra">#define N 32</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">int main () {</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">  int  a[N], b[N];</div><div class="gmail_extra">  int c[N];</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">  for (int i = 0; i < N; ++i)</div><div class="gmail_extra">       c[i] = a[i] + b[i];</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">  int sum=0;</div><div class="gmail_extra">  for (int i = 0; i < N; ++i)</div><div class="gmail_extra">       sum += c[i];</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">  return sum;</div><div class="gmail_extra">}</div><div class=""><br class=""></div></div></div></div></blockquote><div><br class=""></div><div>This will be vectorized without any insertelement, here is a few lines extracted from the output of clang on this code:</div><div><br class=""></div><div>  %wide.load8.6 = load <4 x i32>* %48, align 16, !tbaa !2<br class="">  %49 = add nsw <4 x i32> %wide.load8.6, %wide.load.6<br class="">  %50 = getelementptr inbounds [32 x i32]* %c, i64 0, i64 24<br class="">  %51 = bitcast i32* %50 to <4 x i32>*<br class="">  store <4 x i32> %49, <4 x i32>* %51, align 16, !tbaa !2<br class=""><br class=""></div><div>Because you didn't write the example as I described it, i.e. taking integer, doing a few arithmetic and writing result to contiguous memory, the vectorizer will be able to load directly vectors from memory, operates on them, and store the results. For example try with the following C code:</div><div><br class="">void foo (int a1, int a2, int a3, int a4, int b1, int b2, int b3, int b4, int *res) {<br class="">  res[0] = a1 + b1 * 2;<br class="">  res[1] = a2 + b2 * 2;<br class="">  res[2] = a3 + b3 * 2;<br class="">  res[3] = a4 + b4 * 2;<br class="">}<br class=""><br class=""></div><div><br class=""></div><div>That's for the clang part, you can look at the vectorizer lit test to have examples of IR before/after vectorization.</div><div><br class=""></div><div>-- </div><div>Mehdi</div></div></body></html>