<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/115510>115510</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM doesn't properly optimize swap of larger structs
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
philnik777
</td>
</tr>
</table>
<pre>
This code gets properly optimized to load the values into registers and then stores them back. When changing the buffer size to e.g. 16 bytes the data is moved to the stack instead, even though it could be swapped in the same way with XMM registers, which are used anyways.
```c++
struct S {
char buffer[8];
};
auto test(S& lhs, S& rhs) {
S tmp(lhs);
lhs = rhs;
rhs = tmp;
}
```
(https://godbolt.org/z/o5vYY7Ea5)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxkU8Fu4zgM_Rr6QtSQ5Dh2Dj60zebUnrrYnR5li7E1lS1DlBOkXz-QE7SZGUCQqUc9ks940sy2n4gaKJ-g3Gd6iYMPzTxYN9mPqqqy1ptL8-9gGTtvCHuKjHPwMwV3QT9HO9pPMhg9Oq8NxoHwpN1CjHaKHgP1liMFRj2t2Qk5-kCc4hFb3X3k-H-Cu0FPvZ36tUS7HI8UkO0npdKU9znKLbaXeGWi0VGjZRz96do9gRx194F24kjagHpGOtGEcfBLP6CN2PnFGWwJ-aznmQza6crTI-FZX_Bs44A_Xl-_x05VzoPtBtSBcGEyqKfLWV84B7EH8Xjbt-K6OlBPaa0ox7B0Ed8QqhuSVIabOiifaij3UNxyUN3F666XJIw4gqrfQG3RDetAaxxSvLsrjW8YxxlUvd7afdVKLIRivzK-wHRa0cS5H-F3PbejqocYZ4biEdQB1KH3pvUu5j70oA6foA6-PL2_V__oMrVeSZlpCrMrdjqjRlaFFHWxqTbZ0BSiFkbKWqqShOzq1hS1LI1W3VGaUojMNkqojZSilttCyk1Ou2onZNEWcrsRO6pgI2jU1uXOncY0RGaZF2qkLEspMqdbcrx6Wql0BYrHm1V1tH5iUArUMyg1WmYyD_fJlCv3WWgS8aFdeoaNcJYjf3eLNjpqXl7-e0XjiSdQVfz7Vaw2Q39Ep0Of3LzagbMluOaP32njsLR550dQh3Xg6-dhDv4ndRHUYRXIoA43jadG_QoAAP__JMMqYw">