<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57549>57549</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization computing __int128_t product from mixed uint64_t and int64_t operands
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tspiteri
</td>
</tr>
</table>
<pre>
Although these two functions are equivalent, `foo` uses two multiplications while `bar` uses one.
```c
#include <stdint.h>
__int128_t foo(uint64_t u, int64_t i) {
return (__int128_t) u * (__int128_t) i;
}
__int128_t bar(uint64_t u, int64_t i) {
int64_t ui = u;
__int128_t correction = 0;
if (ui < 0)
correction = (__int128_t) i << 64;
return (__int128_t) ui * (__int128_t) i + correction;
}
```
\[[Compiler explorer](https://godbolt.org/z/7edzEednj)]
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVNtynDAM_Rrz4ukOmPsDD3tJ3_oNOwYEKGMw9SWb5usrk2SzSbozZYyxLB3p6NhDq_s_zV65Sftx4m4CC9xdNB_80jnUi-XSAIffHp-kgsUxceSsiAetaebegt3CZ68crgo7-Qq6TKggBLbSXAP1AjsWn1i8f5uL-HV0b7ZIcemU7wmZHq3rcXG7iaUPt6DzmXYTUZ0dDyRE5ckuMjJ94PZuIBM1Z-XhFcTpMeC8WTghPlKEIE9b--_byNI3MCtPdwiE5v6fwDUMqb0TRac3zpusnTYGNvG3uPhTHA58KxkUIpeoP1zh-YL93lXABWiRfUp7Vxy8ow5tHW6q_UOs98P9dOL5keUHGkc9r3RDDIfnVWkDhuUnKjI5t1qW0k34SWPUfauV22kzkvVCbwn9ywP0y2NoPD9F0CRFIURVlLmI-ibt67SWkUOnoPmF1kLP9epwxpftXhLhefUOl_FW79Xo3nd0nYye-YzPBLoeqVz667npFQzZNvJGNV-Yopt8u6P0ZCj19P75QbkfSSEyiY0HS4u8zLM6mhopxBAPSZHAkNUyq0QNeZl0ZdnLspMDREq2oGwTBBNigQvfUtA6dI6NiIWI6zhL4qROkl0HVSfaKi3yoYRsKFkWwyxR7QKPIGFkmo1S60dLToXW2Q-ntBbHBWArR_mlp1-CaZxd0YHBaKvdbNz_At-HQS4">