<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/131824>131824</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
InstCombine misses freeze of i1 select fold which appears in X86ISelLowering
</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>
arsenm
</td>
</tr>
</table>
<pre>
```
define i1 @src(i8 range(i8 0, 2) noundef %i, i8 range(i8 0, 2) noundef %i1) {
bb:
%loadedv.i.i2.i = trunc nuw i8 %i to i1
%loadedv.i1.i.i = trunc nuw i8 %i1 to i1
%i2 = select i1 %loadedv.i.i2.i, i1 %loadedv.i1.i.i, i1 false
%cond.fr13 = freeze i1 %i2
ret i1 %cond.fr13
}
define i1 @tgt(i8 range(i8 0, 2) noundef %i, i8 range(i8 0, 2) noundef %i1) {
bb:
%i21 = and i8 %i1, %i
%i2 = trunc nuw i8 %i21 to i1
ret i1 %i2
}
```
https://alive2.llvm.org/ce/z/HRpvwJ
I noticed this while looking at random IR samples in X86ISelLowering.cpp's output.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8U8GOmzAQ_RpzsRbZAyRw4JDdCDVVT9tLrzYMZFpjI2wSdb--Mslmm9099FQJCTTMe2_e81h5T4NFrFnxyIp9opZwdHOtZo92TLTrftdsI66P2DGx67Ani5wkZ7nwc8ugpJLPyg54-RQMnjgwqLh1i-2w5wwKisV_6ZOxwLaPTOy0ZllUjHXjVIfdKaWUICXOsj0P82Jbbpdz5I1QHhwnGQF3CBlBnyPkPYRgbfNosA2rw_fCqwv5kf5a75XxeJ24dbZL-1lmK2c_I77gFUuwKs74KnLrjRFv958EHYbwH4K-DCfXiZXtbjFFgpX7PqgPecLfgb7ZW_3efL3bp2MIk4_60DBolKETQmrMaUzdPDBoWmTQvDBovjxPp_PXC-jArQvUYsfDkTw_H8kgN879IjtwFaL7zo388My9GieDnpPlP8rN4Tuab-6MM9khbaeJwdZzt4RpCSlPujrrqqxSCdZym0MmpYAyOdZ5pTY5lp2utOyLShelzmCrMsBMCw0ioRoEFCKTpSzkVmxTVCgF6LytqnbTSs1ygaMiczOWkPcL1jKTJeSJURqNX-8gQGxh2Y6sD60bNVlkAAyeGMBI3mP34KZAI72oQM7Gf8U-mesIe9DL4FkuDPng37QCBYP1wfrwdCHkK5F_3UrXx4O6rn3vTBcDbY9cTROq-bPskmU29f3JDRSOi05bNzJoVg-X18M0u5_YBgbN6tkzaK62TzX8CQAA____g1Tc">