<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/83127>83127</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] InstCombine gets stuck when simplifying selects
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:instcombine,
llvm:hang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
dtcxzyw
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
Reduced test case: https://godbolt.org/z/ds9eq96db
```
define i16 @func(i16 noundef %p_12) {
entry:
%cmp1 = icmp ult i16 %p_12, 2
%and1 = and i16 %p_12, 1
%and2 = select i1 %cmp1, i16 %and1, i16 0
%cmp2 = icmp eq i16 %and2, %p_12
%and3 = select i1 %cmp2, i16 %and1, i16 0
ret i16 %and3
}
```
```
ADD: %and3 = select i1 %cmp2, i16 %and2, i16 0
ADD: %and2 = select i1 %cmp1, i16 %and1, i16 0
ADD: %and1 = and i16 %p_12, 1
IC: Visiting: %and1 = and i16 %p_12, 1
IC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0
IC: Visiting: %and3 = select i1 %cmp2, i16 %and2, i16 0
ADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0
ADD DEFERRED: %cmp2 = icmp eq i16 %and2, %p_12
IC: Mod = %and3 = select i1 %cmp2, i16 %and2, i16 0
New = %and3 = select i1 %cmp2, i16 %and1, i16 0
ADD: %and3 = select i1 %cmp2, i16 %and1, i16 0
ADD: %cmp2 = icmp eq i16 %and2, %p_12
ADD: %and2 = select i1 %cmp1, i16 %and1, i16 0
IC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0
IC: Visiting: %cmp2 = icmp eq i16 %and2, %p_12
IC: Visiting: %and3 = select i1 %cmp2, i16 %and1, i16 0
ADD DEFERRED: %and1 = and i16 %p_12, 1
ADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0
IC: Mod = %and3 = select i1 %cmp2, i16 %and1, i16 0
New = %and3 = select i1 %cmp2, i16 %and2, i16 0
ADD: %and3 = select i1 %cmp2, i16 %and2, i16 0
ADD: %and2 = select i1 %cmp1, i16 %and1, i16 0
ADD: %and1 = and i16 %p_12, 1
IC: Visiting: %and1 = and i16 %p_12, 1
IC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0
IC: Visiting: %and3 = select i1 %cmp2, i16 %and2, i16 0
ADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0
ADD DEFERRED: %cmp2 = icmp eq i16 %and2, %p_12
IC: Mod = %and3 = select i1 %cmp2, i16 %and2, i16 0
New = %and3 = select i1 %cmp2, i16 %and1, i16 0
ADD: %and3 = select i1 %cmp2, i16 %and1, i16 0
ADD: %cmp2 = icmp eq i16 %and2, %p_12
ADD: %and2 = select i1 %cmp1, i16 %and1, i16 0
IC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0
IC: Visiting: %cmp2 = icmp eq i16 %and2, %p_12
IC: Visiting: %and3 = select i1 %cmp2, i16 %and1, i16 0
ADD DEFERRED: %and1 = and i16 %p_12, 1
ADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0
IC: Mod = %and3 = select i1 %cmp2, i16 %and1, i16 0
New = %and3 = select i1 %cmp2, i16 %and2, i16 0
...
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV01vozoU_TVmYxWZaz4XLNJQpC7eW3Txtk-AL8TvgUmxmU7660cQoiZpZqaFVO1ipCjRxed--Pr4hJtpLSuFGBPvlgAIU3x_3j0RAOIlVtabTdvF00Mrb8UufkDRFyioQW1okWkkfEU3xmw14SsCKYG0akXe1sZuu4pA-kwgFTrCx8gXOWEJYSvis-kzmgJLqZBKx6fEZWWvCgLhYKm2VwJLSsDb_usAgYiS4HbvhMp0uyHlaNEBUzRbhxKeUFk0W9rXZh_y4LymcATOlNiDMyXOcc4pDkacxhqLIeQh1YCcHIdgB5OdVgQvFeHjEX5MdMh5ko5fTAe_SdehOVrmU6OD5GLHz8xVkgyn-K4C4KyAsxizejbFeNvp3K8H7D9SSyNVdZx7vuesql-HW9ZGmtyldw8Pd1fp5-tg7-Lkfm9_tWL0WEQQSin9G59G1wVEn8PVX8V4VzuuQfIPZ9_cU75U0tz2ntDubbfyqsxfwNtXynog7SL2H39_MbldLpufLrhLW_lxkvtFBPcacvlHcH_-d_-V5Patt_KyTH-63M5l7WXFtW377JXXEjEXEY8yC2MnYBHjvus71iaOeJl7AYa-i3mBkAdhwErAUGTcYci4JWNg4DKAwAFwmGNHnuuHgpWeIzD0nYC4DJtM1nZdf2uG8ceSWvcYh9yBwKqzHGs9DVoDgvCVVNoUbZNLhcPMBeuXpU2mqmkO6-Lh2U3eV5q4rJba6JcURpp6HN_ulTbrKZaX0COTVmg01aYv_qdPG1RUy2Zby3InVTW1VVt9V8dnc5w0mz63i7YhkI5V7X9utl37HxaGQDruTxNIxy3-CAAA__9aJrzO">