<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/72651>72651</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine][EarlyCSE] Missed optimization for not canonicalizing `select uge/ult, A, B`
</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>
XChy
</td>
</tr>
</table>
<pre>
Alive2 proof: https://alive2.llvm.org/ce/z/mLG22y
Missed example: https://godbolt.org/z/5j3hjYY3o
### Description:
`select ult, A, B` could be canonicalized to `select uge, B, A`. But in this example, it's not canonicalized, and further, can not be eliminated by EarlyCSE or GVN.
### Real-world motivation
This snippet of IR is derived from zstd/.../extr_zstd_lazy.c_ZSTD_insertDUBT1.c (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also: https://godbolt.org/z/absa5fqEb
**Let me know if you can confirm that it's an optimization opportunity, thanks.**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMFu4zYQ_RrqMoggUVYUHXRw7GgRYNsCu2nR7SUYSSNrshSpkiPv2l9fSE52k7SHAgQNemYe37zhE4bAB0tUqfxW5fsIZxmcr_7cDaeocd2p2ho-kobJO9erbAuDyBRUtlW6VrrGNRobcxxj5w9K1y0pXZ-VrsePH7Q-qWSvku0vHAJ1QN9xnAz9G-bgusYZeYZYqvOnbHj68iVzF4DnXWeXBXsKredJ2NkF5BK9TgIZagVmI0rvYLtst-o6gdbNpoOGoEXrLLdo-EwdiINXRQe65K-V10kMt7MAW5CBww_qegcsShcBrJO3cEsMbQf97GUgvxxbtGteQ0CGR7Yo1EFzgjv05rT7fAfOw4c_fo3_u8tPhObqm_Omg9EJH3Ht91Xqw0ItWJ4mEnA93H8CDtCR5yN10Hs3wjlIp3Qdx7HSNX0X_7j882jwfIrbx78-P-wf2Qbysv_99iGNW1D6BnshD79lMPFEhi0pXcYvN9KLFoCNO9JyIYKnbm6pgyP5wM7GcN_Dyc1KF56ArZCnsLS-ykngPB_YooEwN24SHtEs3Bf1fh4XAQMRoAnu_zwZbALm_d93zVsxl_WRBEaCr9Z9A16ZraNpne3ZjyADystY0V4o8HlVG9w0OS-zZTkthGRA-zXEF9ioq7KuzEqMqEqLJNFZkm50NFR9UzZ93ia4KbBNsbgp8k2WtmXW3JTYFWnElU50lqZpkW6SMtFxudl0lFBRYnmD2KLaJDQimx_WijiEmapCX-dpZLAhE1bPar1kqGzLNkjrxmYdl1Z6p7QeV99dvW5oieX7yFdL2VUzH4LaJIaDhJ9XCYtZvwj3NsjuGTPfq_z25d2qfA_Ppn6jVu_8e2OwPbx3Wf3eoNHsTfVuvizD3MStG5Wu1xYvP1eTd0_UitL1qkhQul5F-ScAAP__GlGJfQ">