<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/76441>76441</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect instcombine optimization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ericastor
</td>
</tr>
</table>
<pre>
Demonstration in alive2: https://alive2.llvm.org/ce/z/B5daAG
The function
```
define i128 @f(i128 %x) {
entry:
%0 = and i128 %x, 36893488147419103231
%1 = xor i128 %0, -1
%2 = and i128 %1, 36893488147419103231
%3 = xor i128 %x, -1
%4 = and i128 %3, 36893488147419103231
%5 = add i128 %2, %4
%6 = and i128 %5, 36893488147419103231
ret i128 %6
}
```
incorrectly optimizes to:
```
define i128 @f(i128 %x) {
entry:
%0 = shl i128 %x, 1
%1 = sub i128 18446744073709551614, %0
%2 = and i128 %1, 36893488147419103230
ret i128 %2
}
```
which disagrees on input 0.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslN9unDwQxZ_G3FhZ2WOD4YKLzbfiU-_7AgYPiyvAK9sku3n6ij_dbETURlUlBNic85M1hxkdgj2PiCVJn0l6SvQUO-dL9LbRITqf1M7cyhMObgzR62jdSO1IdW9fEIg40i7GSyDiSKAiUK37h75_GQ7OnwlUDRKo3ghUz6nRx_8JOxF2XO_fO6TtNDYzdNvP2HYtS4OtHZFaDjklkrUE8vUd0iuBghL1vApxjP42H2JZ0VnAKBEnqkdDHyz_UZHlhZB5zqWSvOBMgOAPLr64rs7fXWx2PT1qYEfmXyCLHfm6I8sdWXyBnK4u8-6C2TXzHlTZjp3-ie0x3sXZFpA6fZqUHRvnPTaxv1F3iXawbxhodPdM_nmyoes_VnIfY5jqVcJzKTMlJVNCsSJNecblViL2V8Gyz0oEvy_Ra2ebjhob9NkjBro00mWKlB0SUwpTiEInWHLFRJbnXEHSlVqhEHlTZK1CnXJTC5Zygy1ra8wQ68SWwEBwAMWlhJQf2lbWXHGDyrRa1ZxIhoO2_b0lExvChKXKpORJr2vsw9L7ACO-0uUjAZhHgS9nz1M9nQORrLchhndKtLHH8tuv2KkdQ2zcUM-pbj_AMiySyfflxxlxtrGb6kPjBgLVDNweTxfvfmATCVTLMQKBajnmzwAAAP__Hbk4CA">