<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69001>69001</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[x86] The x86 backend seems to break the cse optimizations
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ZY546
</td>
</tr>
</table>
<pre>
For the following test cases, `cse` has been done in llvm ir, but on x86, the final assembler code seems to break this optimization:
https://godbolt.org/z/EYc9c66jK
```cpp
extern int x, y;
void test(int a, int b) {
x = a + b + 1;
y = a + b + 2;
}
```
```llvm
define dso_local void @test(int, int)(i32 noundef %a, i32 noundef %b) local_unnamed_addr {
entry:
%add = add nsw i32 %b, %a
%add1 = add nsw i32 %add, 1
store i32 %add1, ptr @x, align 4
%add3 = add nsw i32 %add, 2
store i32 %add3, ptr @y, align 4
ret void
}
```
```asm
test(int, int): # @test(int, int)
lea eax, [rsi + rdi]
inc eax
mov rcx, qword ptr [rip + x@GOTPCREL]
mov dword ptr [rcx], eax
lea eax, [rsi + rdi]
add eax, 2
mov rcx, qword ptr [rip + y@GOTPCREL]
mov dword ptr [rcx], eax
ret
```
Maybe `lea eax, [rsi + rdi]` should not be repeated twice.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVV1v2zYU_TXUy0UN6erD0YMe4rjewzZsGPrSvQT8uLLY0qRHUrHdXz-QypI6SbcVqGGQJu_R0Tm8xDEPQe8t0cDaDWu3BZ_j5Pzw58e26Qrh1GXYOQ9xIhidMe6k7R4ihQiSBwoM74B1pQzEuhImHkAQWVDOEmgLxjwcQPuEEnMEZ-F806VV5tOWG-Ah0EEY8iCdIghEhwDRgfDEP0OcdAB3jPqgv_ConWX1LSu3rLydYjyGtMIdw93eKeFMXDm_Z7j7wnD3_qPsZdd9-nmBs65cvvJ4XHboHMlb0DbCOUm6sHqzVB6cVtkjw5tU5qmcfgiGPbD1I2wZAQDOwOotcGC4AZHH6oks1S-v6vhUZ-vtC4UvlukMly1Fo7YEKrh74yQ3kIWypnzW-qiUYZ_WNYJ1s1U0AsN2sXG9lx1lsvvZWn4gdc-V8s8myUZ_eTp0yDxKLX6UAhtOmXKhultecwWt3sJypRK6-gcaovP0VbFK1WP0yVxuDjd6b6G5pq7_hRq_RV1_RX15g9pTzOf6P7vDw2Nz3uxBfQsM62-26OmCpI8hnmfi2TFrNz7ofFm80qzdXqO1lRl5tXlwD3n2MlP8dXJeLV7bjdfHTHZmTfnTbx9-v_vj_S-vWBOBunpKnhMI716_7Pv0pi49IvH7RV9-lGhP8e1-5vFXfhGU8uw_vXUlhMnNRoF1EQSBpyPxSAriSUtaFWqoVV_3vKCh6vo1VhWuq2Ia1kLRGrFBJaquVKNolBqx76uR9yS7sdADllhXZVVXbd1gu-o5H2vJb3rVj21Tlawp6cC1WaVgSIFX6BBmGrq-LKvCcEEm5DBHtHSCXGSIKdv9kJ55J-Z9YE1pdIjhmSXqaPK_QIrodgsfJkppDYLLz2TV62QmkIGuwjkUszfDi2TWcZrFSroDw13OsmV6d_TuE8nIcJclBoa7bOHvAAAA__-LzNp4">