<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54718>54718</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization with 32-bit adds and shifts
</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, the code generated for `bar` is [slightly better](https://godbolt.org/z/49qj5a1a4).
```c
#include <stdint.h>
int32_t foo(int64_t a, int32_t b, int cond) {
if (cond)
a += ((int64_t) b) << 32;
return a >> 32;
}
int32_t bar(int64_t a, int32_t b, int cond) {
int32_t r = a >> 32;
if (cond)
r += b;
return r;
}
```
Note that when using 64/128 bits instead of 32/64 bits, the optimization is found and the code generated is [the same](https://godbolt.org/z/8vPseqqc3).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydlM1u2zAMx59GvggNbMmfBx_aprlt2BsMkkXbKhQrkegG7dOPdpIG2YphGEDZpiiRP1p_W3vz3j46HP08jBxHiMDx5Hk_Tx1aP0WuAnA4zvZNOZiQiedlFe-8AT7ABEEhGN77wFmZahXoym3krHiKzg4juneuARECK7ZM1CPiITL5yMSObPBGe4cbHwbyPmjkzfG1UJnKmWg2LN2y9JEynq27-ELaqXMzATD5HNHYCTcjky_nMHlS_ERC8lSPvDInTy3g15C-ONTFZKgQZ9XTJXfa2J7Tvkvkc5ZM0fwTk9slfMu8bNdrDvlMxqVg8pYsAM5h4rSV8OTLXbTa3gMvL--_gC-L6AQI7stSf-kqXLvSX3CHP2k_T-PsfvdIghkV8tMIE5-jnQZe0untMlFzbTESd0RQhvt-YRK7Ml_nr0ryB7R7-6EWtS3K6f08Ga5ofKGzs7KWQFR7-DdJ1W8_IhyPnVwklZhWmkY2KkGLDtpvNkbKewdxsjgS6gNRcmVMXGHiaHuMyRxc-1tBWj3rTef35Dj3dr09HIJ_hY4EsqMaM1DDuyKvsjoZ21rXWV-lNcjMZJUo-gLKvs6NMbIqdQOJUxpcbKlXJsQEJ76moGdqObGtSIVI81Rkosik2IDQWldVaZrG5KKpWZ7CXlm3WTiWN5GEdkXS8xAp6GzEeAuqGO0wAazlKL-a6XcQWowHS9-tTdba7cr-C2PtP18">