<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jun 17, 2016 at 9:38 PM, Sanjoy Das via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: sanjoy<br>
Date: Fri Jun 17 23:38:31 2016<br>
New Revision: 273079<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=273079&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=273079&view=rev</a><br>
Log:<br>
[SCEV] Fix incorrect trip count computation<br>
<br>
The way we elide max expressions when computing trip counts is incorrect<br>
-- it breaks cases like this:<br>
<br>
```<br>
static int wrapping_add(int a, int b) {<br>
  return (int)((unsigned)a + (unsigned)b);<br>
}<br>
<br>
void test() {<br>
  volatile int end_buf = <a href="tel:2147483548" value="+12147483548">2147483548</a>; // INT_MIN - 100<br>
  int end = end_buf;<br>
<br>
  unsigned counter = 0;<br>
  for (int start = wrapping_add(end,  200); start < end; start++)<br>
    counter++;<br>
<br>
  print(counter);<br>
}<br>
```<br>
<br>
Note: the `NoWrap` variable that was being tested has little to do with<br>
the values flowing into the max expression; it is a property of the<br>
induction variable.<br></blockquote><div><br></div><div>It seems like it should be possible to optimize nsw-tripcount.ll *somehow*... you're right that the NoWrap on the induction variable is irrelevant, but it should be possible to use the NSW property of the RHS to come up with the right conclusion.<br><br></div><div>-Eli<br></div></div></div></div>