<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63749>63749</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] Missing and of icmp fold
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:instcombine,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nikic
</td>
</tr>
</table>
<pre>
Missing this fold: https://alive2.llvm.org/ce/z/5Hlb2C
```llvm
define i1 @src(i8 %x, i8 %y) {
%add = add i8 %x, 1
%c1 = icmp ne i8 %x, -1
%c2 = icmp ule i8 %add, %y
%and = and i1 %c1, %c2
ret i1 %and
}
define i1 @tgt(i8 %x, i8 %y) {
%c = icmp ult i8 %x, %y
ret i1 %c
}
```
This can also be seen as a two-step fold with the intermediate step:
```llvm
define i1 @tgt(i8 %x, i8 %y) {
%add = add i8 %x, 1
%c1 = icmp ne i8 %x, -1
%c2 = icmp ult i8 %x, %y
%and = and i1 %c1, %c2
ret i1 %and
}
```
Where we can replace `x + 1 <= y` with `x < y` because we know `x != -1` from the first and condition.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VMGOozgQ_ZriYiUyRYBw4JBOhHYPe1tpzsYugqfBjrDpdPfXj2ySCRlppD7MSAgj1yu_V_VMCef02RDVkL9AfkrE7Hs71Ua_apm0Vn3U_2nntDkz32vHOjsoyA6s9_7iIDsANoCNGPQb4XYY3satnc6AjSTA5hOwyf8ZWjwCPwE_3N4FX54AX7YUddoQ0ymDHXeTBNzrPQPM3wGPbPn8AKwYlC9LBgtbQikG2YmFdYVPVxCZRoSW44UFhgdq8wTDB2we7jihVEBG8hWrubEaFRUHkhtM4h03kb8FhVG3usvTug1PNfuz_2LNci3Urwtay3zQy1_J791fa_k_WCuFYWJwlrXEHJFhwjHB_NVunKdLdJ5dte-Z74lp42kaSWnhiYV4uAtfsvdrpf5Fd3_btD_i7XN7v_U0EbtSbO5El0FIYlDwdwb4woL6Y6D7gIIvvV1i2XHZakmK2cUDXo293jPTkLNJA6Kb7BgN6fTkfNQtrVHaa2u2iaozVWWVSKhOi_2-LErcV0lfl2nbdWLXUZsWJbWpTLO9Ktu8ynZiz3OZ6Bo5ZrzkJSJPsdp2bSE4l53AKiu7Ygc7TqPQw89_PtHOzVQXWbmrkkG0NLg4UhDjPcgO2jgv7dhqQ4AIeATEUTtHamMvXo_6UwTRIZafkqkOaZt2PjvY8UE77x5UXvshDqx_jfPH25n5id0nVeiC7Ra_w7VN5mmonyfWWft-brfSjoBNVLgsm8tkv5P0gE0syAE2saYfAQAA__9T2G9N">