<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54840>54840</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Failure to recognise a decremented value is within a known value range
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:optimizations
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          RKSimon
      </td>
    </tr>
</table>

<pre>
    Another case pulled out of Issue #37628 - we fail to recognise that the unsigned value '%count' is less than 8, which should let us fold away the remainder code entirely as the select code will allow us to ignore the case where count == 0:
```
----------------------------------------
define i32 @src(i32 %start) {
  %count = and i32 %start, 7
  %eq0 = icmp eq i32 %count, 0
  %dec = add i32 %count, -1
  %and = and i32 %dec, -8
  %res = select i1 %eq0, i32 0, i32 %and
  ret i32 %res
}
=>
define i32 @tgt(i32 %start) {
  ret i32 0
}
Transformation seems to be correct!
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNU8GSnCAQ_Rq8dM0Uos7owcPsTrYqlVuSH0BBJUGYBVxr8_VpGGcz2aRSsSht7NeP5vHorHhtT8aGSTrouZdwWbSWAuwSwA7w0ftFAmFFcTywGnawShi40hAsONnb0SisCRMP-JKwGK9Gg-UvXKe6I2FVbxcTMATlQUvvI9xATdgjrJPqJ_CTXbTAXIDFw2Ax5it_TYxOzlwZEbuzQoI0QTmpX4H7lPZSyz5cc6vSGrjWdo002CC2Yp1MuLS1FTeJYWwHSHHGAZQUJ0LPhJ7IgW4jTXf_-VzRQg7KSFAFA1JS73rC6jRhlQ_c4e4bIMeHKxjgJkrsArgR8Dv2EY53SPlME0718wXk8w27qfoI9A4rZH_lFOIP3C6_A8ZF3y2OtQlW38Gc9Am2yazyraEIjGVvwZXyVunwJLe_yLDpezxvQVT-w990C2P4t243XvqO8qvjxg_WzTwoa7BbOScDdPG0HfoUifJ3x5yJthBN0fAsqKBl-4SuXqJb7o3NAVVBC6Lt3kyNLl5VmJTB7HdjV7P9xx5GmS1Ot1MIFx-NxZ5wjAheun1vZ5xo_XL77C7OfkutPal4yzwGVVmXNJta3hzzgZeHsiqaOj_krKkrKljd9yUrGzpkmndS-5ZUD4SxRFqc7CWoWf1IGiAZI9U5Uy2jjNEyp3nNyrzc07ypez50jRzYMHQ5yh5vmN5Hkr11Y-ba1F23jB6TWvngfyW5TxdcppWRny9hsq79_OmLmq3J0kbatIufElNLYw">