<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/90668>90668</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Miscompilation of some forms of (x + y) * z
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
glandium
</td>
</tr>
</table>
<pre>
Reduced testcase:
```
#include <stdint.h>
#include <stddef.h>
size_t off(int8_t a) {
return (uint8_t)(a + 128) * 8;
}
```
With clang 18, this compiled down to:
```
add dil, -128
movzx eax, dil
shl eax, 3
ret
```
With trunk, this compiles down to:
```
movzx eax, dil
lea eax, [8*rax + 1024]
ret
```
The math in the lea is actually fine, transforming (a+128) * 8 into 8 * a + 1024. But the problem is that a is zero extended instead of sign extended, so the results are wrong for negative values.
Bisection says it started happening with 7177dc2ef7f3a50a1d8b892d7bd298f3d52a1aab.
Cc: @fengfeng09
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMuOrDYQ_RqzKU0L7AbMgkX3THqXTRQpy6sCF-DE2C27mNfXR6Y7NzNRRhoLbFl16tSph4wp2dkT9aI-i_qpwI2XEPvZoTd2W4shmLf-NzLbSAaYEo-YSKiTKJ9EeRJNef9uV6msH91mCIR6TGys58Mi1C9fmA1NH837nuw7_WAI0ySktp71DwYUsgPRnm8IAIBIvEUPQurthhGyE1IjCHmGSurdQZ5AC3X3Eu3T_2r-w_ICo0M_Q6WFfARebIIxrFfryIAJLx44fJUx3Bcas5_GuszxkCV8Aqzh-f0VAAhfMyDjbva0uB1wN6jPbpH4a9UcN__XfyWn70r-UtF9OcKPwkR91kKeIr7ealzKo6ifvqf2tv--EKzIC1gPvNAewCbAkTd07g0m62nPJqJPU4ir9XPuMAp5_thSsJ4D6P2CP8Uc4LzxznuNYXC0Zm5ekGGP8k4xAL0yeUMGrE9MaCBMkMf_pyGHT2FniZQ2xwkwErzE4GeYQgRPM7J9JnhGt1E6fMzvbBONbIOHhG8JLENijEwGFrxeyed0XnLf2qptzShpaieFdYmV0YPupGkHIzs9KVNLrBCHT-yPo1AnEMdyIj_nv-wK0yvTqQ4L6qu2OtZV1VR1sfRG1o1qK5oaU2kt26asqZGoKimnTlFX2F6W8lgeVSmrSqn60LR12WqqyqM2WuEgjiWtaN3Buef1EOJc2JQ26ruyaXThcCCX9idDSk8vsBuFlPkFiX32eRi2OYlj6Wzi9C8LW3bU_2rTbVpxL1fuQlgpF3hN-Sakvk3Z2z9Nfy-26PqF-ZryXMuLkJfZ8rINhzGsQl5yhPvxcI3hTxpZyMuuKwl52XX_HQAA___ZcWwY">