<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10px"><div id="yiv3169423225"><div id="yui_3_16_0_1_1429696167899_14877"><div id="yui_3_16_0_1_1429696167899_14876" style="color:#000;background-color:#fff;font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:16px;"><div id="yiv3169423225yui_3_16_0_1_1429696167899_5198" style="" class="yiv3169423225">Hi,</div>
<div style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_2496" dir="ltr"><br></div><div id="yiv3169423225yui_3_16_0_1_1429696167899_5186" style="" class="yiv3169423225" dir="ltr">I am trying to understand the limitations of the current vectorizer, and came upon these test cases that fail to get vectorized.</div><div id="yiv3169423225yui_3_16_0_1_1429696167899_5185" style="" class="yiv3169423225" dir="ltr"><br style="" class="yiv3169423225"></div>
<div style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_2934" dir="ltr">1. loop1 below (<font style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_3661" color="#cd232c"><span style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_3071">note the increment by 2</span></font>)
 fails to get vectorized because the access <font face="Courier New, courier, monaco, monospace, sans-serif">a[j+1]</font> is considered to wrap
 around (the corresponding SCEV doesn't have nsw/nuw set) and hence <font style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_3509" face="Courier New, courier, monaco, monospace, sans-serif">isStridedPtr</font>() in <font style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_3658" face="Courier New, courier, monaco, monospace, sans-serif">LoopAccessAnalysis.cpp</font> return false. <br></div><div id="yiv3169423225yui_3_16_0_1_1429696167899_4950" style="" class="yiv3169423225" dir="ltr"><br style="" class="yiv3169423225"></div>
<div style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_2497"><font style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_2910" face="Courier New, courier, monaco, monospace, sans-serif" size="2">#define SIZE 100000<br style="" class="yiv3169423225">void loop1 (float a[SIZE])<br style="" class="yiv3169423225">{<br style="" class="yiv3169423225">  long t, j;<br style="" class="yiv3169423225">  float cc = 23, dd = 34, ee = 233;<br style="" class="yiv3169423225">#pragma clang loop vectorize(enable)<br style="" class="yiv3169423225">  for (j = 1; j < SIZE-1; j += 2) {<br style="" class="yiv3169423225">    float x;<br style="" class="yiv3169423225">    x = a[j+1] + ee;<br style="" class="yiv3169423225">    x = x / dd;<br style="" class="yiv3169423225">    x = (cc + x) / dd;<br style="" class="yiv3169423225">    a[j] = x + 2 ;<br style="" class="yiv3169423225">  }<br style="" class="yiv3169423225">}</font><br style="" class="yiv3169423225"><span style="" class="yiv3169423225"></span></div>
<div id="yiv3169423225yui_3_16_0_1_1429696167899_4899" style="" class="yiv3169423225" dir="ltr"><br style="" class="yiv3169423225"><span style="" class="yiv3169423225"></span></div>
<div style="" class="yiv3169423225" dir="ltr" id="yiv3169423225yui_3_16_0_1_1429696167899_3285">2. Of the two loops below, the loop "<font id="yiv3169423225yui_3_16_0_1_1429696167899_4971" style="" class="yiv3169423225" face="Courier New, courier, monaco, monospace, sans-serif">works</font>" gets vectorized, while the loop "<font id="yiv3169423225yui_3_16_0_1_1429696167899_5009" style="" class="yiv3169423225" face="Courier New, courier, monaco, monospace, sans-serif">fails</font>" does not get vectorized.</div>
<div style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_3397" dir="ltr"><font style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_3381" face="Courier New, courier, monaco, monospace, sans-serif" size="2">#define SIZE 10000<br style="" class="yiv3169423225">int a[SIZE+4] = {};<br style="" class="yiv3169423225">void works(unsigned long m, unsigned long n)<br style="" class="yiv3169423225">{<br style="" class="yiv3169423225">  long j;<br style="" class="yiv3169423225">  // SCEV can compute the exit value for this loop                                   <br style="" class="yiv3169423225">  for (j = m; j < n+1; j += 1) {<br style="" class="yiv3169423225">    a[j] = a[j+1] + 2;<br style="" class="yiv3169423225">  }<br style="" class="yiv3169423225">}<br style="" class="yiv3169423225">void fails(unsigned long m, unsigned long n)<br style="" class="yiv3169423225">{<br style="" class="yiv3169423225">  long j;<br style="" class="yiv3169423225">  // SCEV cannot compute the exit value for this loop                             <br style="" class="yiv3169423225">  for (j = m; j <= n; j += 1) {<br style="" class="yiv3169423225">    a[j] = a[j+1] + 2;<br style="" class="yiv3169423225">  }<br style="" class="yiv3169423225">}</font></div><div id="yiv3169423225yui_3_16_0_1_1429696167899_4945" style="" class="yiv3169423225" dir="ltr"><br style="" class="yiv3169423225"></div><div id="yiv3169423225yui_3_16_0_1_1429696167899_4922">
The
 only difference between the two loops is the loop exit condition, both 
semantically same. Scalar Evolution is unable to determine the exit 
value of the second loop, leading to the vectorizer failing to 
vectorize. It seemed to me that this is due to <font style="" class="yiv3169423225" id="yiv3169423225yui_3_16_0_1_1429696167899_3656" face="Courier New, courier, monaco, monospace, sans-serif">ScalarEvolution::SimplifyICmpOperands</font> failing to canonicalize the corresponding <font style="" class="yiv3169423225" face="Courier New, courier, monaco, monospace, sans-serif">ICMP_ULE</font> instruction.</div><div id="yiv3169423225yui_3_16_0_1_1429696167899_4897"><br></div><div id="yiv3169423225yui_3_16_0_1_1429696167899_4898" dir="ltr">Thanks,</div><div id="yui_3_16_0_1_1429696167899_14990" dir="ltr"><br></div><div id="yiv3169423225yui_3_16_0_1_1429696167899_5110" dir="ltr">- Vaivaswatha</div><div id="yiv3169423225yui_3_16_0_1_1429696167899_5109" dir="ltr"><br></div></div></div></div></div></body></html>