<div dir="ltr">Hi all,<br><br>I am noticing a significant degradation in execution performance in loops with just one backedge than loops with two backedges.  Unifying the backedges into one will also cause the slowdown.<div><br></div><div>To replicate this problem, I used the C code in <a href="https://gist.github.com/sklam/11f11a410258ca191e6f263262a4ea65">https://gist.github.com/sklam/11f11a410258ca191e6f263262a4ea65</a> and checked against clang-3.8 and clang-4.0 nightly.  Depending on where I put the "increment" code for a for-loop, I can get 2x performance difference.</div><div><br></div><div>The slow (but natural) version:</div><div><div><br></div><div>    for (i=0; i<size; ++i) {</div><div>        ai = arr[i];</div><div><br></div><div>        if ( ai <= amin ) {</div><div>            amin = ai;</div><div>            all_missing = 0;</div><div>        }</div><div>    }</div><div><br></div><div>The fast version:</div><div><div><br></div><div>    for (i=0; i<size;) {</div><div>        ai = arr[i];</div><div>        ++i;        // increment moved here</div><div>        if ( ai <= amin ) {</div><div>            amin = ai;</div><div>            all_missing = 0;</div><div>        }</div><div>    }</div></div><div><br></div><div>With the fast version, adding a dummy line after the if-block will make the code slow again:</div><div><br></div><div><div>    for (i=0; i<size;) {</div><div>        ai = arr[i];</div><div>        ++i;</div><div>        if ( ai <= amin ) {</div><div>            amin = ai;</div><div>            all_missing = 0;</div><div>        }</div><div>        i;  // no effect</div><div>    }</div></div><div><br></div><div>At first, I noticed the problem with any opt level >= O1.  In an attempt to narrow it down, I found that using `opt -simplifycfg -sroa -simplifycfg` will trigger the slowdown.  Removing the second simplifycfg solves it and both versions of the code run fast.  </div><div><br></div><div>Is there a known issue for this? Or, any idea why?</div><div><br></div><div>Regards,</div><div>Siu Kwan Lam</div></div><div><br></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Siu Kwan Lam<div>Software Engineer</div><div>Continuum Analytics</div></div></div>