<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10px"><font id="yui_3_16_0_1_1429701360174_13212" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif" size="3">>have you tried writing code for that, and confirmed that it's actually better than just straight loop?</font><div dir="ltr" id="yui_3_16_0_1_1429701360174_12366"><span id="yui_3_16_0_1_1429701360174_12935"><font id="yui_3_16_0_1_1429701360174_12934" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif"><font id="yui_3_16_0_1_1429701360174_12933" size="3">The same loop gets vectorized on icc and runs faster hence.</font></font></span></div><div id="yui_3_16_0_1_1429701360174_14271" dir="ltr"><span id="yui_3_16_0_1_1429701360174_12935"><font id="yui_3_16_0_1_1429701360174_12934" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif"><font id="yui_3_16_0_1_1429701360174_12933" size="3"><br></font></font></span></div><div id="yui_3_16_0_1_1429701360174_14760" dir="ltr"><span style="" class="" id="yui_3_16_0_1_1429701360174_12935"><font style="" class="" id="yui_3_16_0_1_1429701360174_12934" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif"><font style="" class="" id="yui_3_16_0_1_1429701360174_12933" size="3">Also, </font></font></span><span id="yui_3_16_0_1_1429701360174_12935"><font id="yui_3_16_0_1_1429701360174_12934" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif"><font id="yui_3_16_0_1_1429701360174_12933" size="3">as an experiment, I tried forcing <font style="" class="" id="yui_3_16_0_1_1429696167899_3517" face="Courier New, courier,        monaco, monospace, sans-serif">isStridedPtr</font>() to return
      true. The vectorizer proceeds to vectorize the loop, but does a
      poor job. Instead of using vector Load/Store instructions and
      packing/unpacking, it uses scalar Load/Stores instructions and
      packs them for the arithmetic operations. Note that without the pragma, the cost model does advice against the vectorization. My reason for forcing vectorization was that it did well on icc.</font></font></span></div><div id="yui_3_16_0_1_1429701360174_15003" dir="ltr"><br><span id="yui_3_16_0_1_1429701360174_12935"></span></div><div id="yui_3_16_0_1_1429701360174_15976" dir="ltr"><span id="yui_3_16_0_1_1429701360174_12935"><font id="yui_3_16_0_1_1429701360174_12934" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif"><font id="yui_3_16_0_1_1429701360174_12933" size="3">On icc, I tried the above loop without any pragmas and saw that the loop was vectorized. Also using the pragma "novector" resulted in the loop not being vectorized. With vectorization, performance was better. <br></font></font></span></div><div id="yui_3_16_0_1_1429701360174_15986" dir="ltr"><span id="yui_3_16_0_1_1429701360174_12935"><font id="yui_3_16_0_1_1429701360174_12934" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif"><font id="yui_3_16_0_1_1429701360174_12933" size="3"><br></font></font></span></div><div id="yui_3_16_0_1_1429701360174_15987" dir="ltr"><span id="yui_3_16_0_1_1429701360174_12935"><font id="yui_3_16_0_1_1429701360174_12934" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif"><font id="yui_3_16_0_1_1429701360174_12933" size="3">Thanks,<br></font></font></span></div><div id="yui_3_16_0_1_1429701360174_12367"><font face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif" size="3"> </font></div><div id="yui_3_16_0_1_1429701360174_12360"><div id="yui_3_16_0_1_1429701360174_12359"><font face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif" size="3">- Vaivaswatha</font></div></div><font face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif" size="3">  </font><br><div id="yui_3_16_0_1_1429701360174_14268" class="qtdSeparateBR"><br><br></div><div style="display: block;" id="yui_3_16_0_1_1429701360174_13744" class="yahoo_quoted"> <div id="yui_3_16_0_1_1429701360174_13743" style="font-family: Courier New, courier, monaco, monospace, sans-serif; font-size: 10px;"> <div id="yui_3_16_0_1_1429701360174_13742" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif; font-size: 16px;"> <div id="yui_3_16_0_1_1429701360174_13741" dir="ltr"> <font id="yui_3_16_0_1_1429701360174_13740" face="Arial" size="2"> On Wednesday, 22 April 2015 4:46 PM, mats petersson <mats@planetcatfish.com> wrote:<br> </font> </div>  <br><br> <div id="yui_3_16_0_1_1429701360174_14040" class="y_msg_container">In your first case, I fail to see what the obvious vectorisation would<br clear="none">be - you are reading one and writing one of the every other element -<br clear="none">that is not very easy to made into vectorized operatioons - have you<br clear="none">tried writing code for that, and confirmed that it's actually better<br clear="none">than just straight loop?<br clear="none"><br clear="none">--<br clear="none">Mats<br clear="none"><div class="yqt2357257523" id="yqtfd49241"><br clear="none">On 22 April 2015 at 12:01, Vaivaswatha N <<a shape="rect" ymailto="mailto:vaivaswatha@yahoo.co.in" href="mailto:vaivaswatha@yahoo.co.in">vaivaswatha@yahoo.co.in</a>> wrote:<br clear="none">> Hi,<br clear="none">><br clear="none">> I am trying to understand the limitations of the current vectorizer, and<br clear="none">> came upon these test cases that fail to get vectorized.<br clear="none">><br clear="none">> 1. loop1 below (note the increment by 2) fails to get vectorized because the<br clear="none">> access a[j+1] is considered to wrap around (the corresponding SCEV doesn't<br clear="none">> have nsw/nuw set) and hence isStridedPtr() in LoopAccessAnalysis.cpp return<br clear="none">> false.<br clear="none">><br clear="none">> #define SIZE 100000<br clear="none">> void loop1 (float a[SIZE])<br clear="none">> {<br clear="none">>   long t, j;<br clear="none">>   float cc = 23, dd = 34, ee = 233;<br clear="none">> #pragma clang loop vectorize(enable)<br clear="none">>   for (j = 1; j < SIZE-1; j += 2) {<br clear="none">>     float x;<br clear="none">>     x = a[j+1] + ee;<br clear="none">>     x = x / dd;<br clear="none">>     x = (cc + x) / dd;<br clear="none">>     a[j] = x + 2 ;<br clear="none">>   }<br clear="none">> }<br clear="none">><br clear="none">> 2. Of the two loops below, the loop "works" gets vectorized, while the loop<br clear="none">> "fails" does not get vectorized.<br clear="none">> #define SIZE 10000<br clear="none">> int a[SIZE+4] = {};<br clear="none">> void works(unsigned long m, unsigned long n)<br clear="none">> {<br clear="none">>   long j;<br clear="none">>   // SCEV can compute the exit value for this loop<br clear="none">>   for (j = m; j < n+1; j += 1) {<br clear="none">>     a[j] = a[j+1] + 2;<br clear="none">>   }<br clear="none">> }<br clear="none">> void fails(unsigned long m, unsigned long n)<br clear="none">> {<br clear="none">>   long j;<br clear="none">>   // SCEV cannot compute the exit value for this loop<br clear="none">>   for (j = m; j <= n; j += 1) {<br clear="none">>     a[j] = a[j+1] + 2;<br clear="none">>   }<br clear="none">> }<br clear="none">><br clear="none">> The only difference between the two loops is the loop exit condition, both<br clear="none">> semantically same. Scalar Evolution is unable to determine the exit value of<br clear="none">> the second loop, leading to the vectorizer failing to vectorize. It seemed<br clear="none">> to me that this is due to ScalarEvolution::SimplifyICmpOperands failing to<br clear="none">> canonicalize the corresponding ICMP_ULE instruction.<br clear="none">><br clear="none">> Thanks,<br clear="none">><br clear="none">> - Vaivaswatha</div><br clear="none">><br clear="none">><br clear="none">> _______________________________________________<br clear="none">> LLVM Developers mailing list<br clear="none">> <a shape="rect" ymailto="mailto:LLVMdev@cs.uiuc.edu" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a shape="rect" href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br clear="none">> <a shape="rect" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><div class="yqt2357257523" id="yqtfd57562"><br clear="none">><br clear="none"></div><br><br></div>  </div> </div>  </div></div></body></html>