<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111794>111794</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
With -Oz Clang should emit xchg instruction
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rilysh
</td>
</tr>
</table>
<pre>
For example, doing a bitwise not operation LLVM emits `mov` instruction instead of `xchg` when `-Oz` (optimize for size is enabled). `xchg` r32/32 requires 1 byte, where `mov` r32/32 2 bytes to encode.
Clang generated (with -Oz) https://godbolt.org/z/sPrTbx9sb
```asm
f:
mov eax, edi
not eax
ret
```
With -Oz first `mov` instruction should be replaced with a `xchg`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0UkGPnDwM_TXhYi0KhmHgkMN-u-K0n9pD1Z4TYiBVINMkzMzur6_C0O3sSkWI2PjZec-2DMGMC5Fgh__Y4TmTa5ycF97Y1zBlyulX0TkPdJXzyRLDJ9DOLCNIUCZeTCBYXAR3Ii-jcQu8vHz_H2g2MQCr-ezOrOZglhD92m-AZJPU4IYEuPbTmBCXiZbkP3x5Sy7Dxp2imc0bweA8hGSYALRIZUkzbPP7bF8iw65E8PRrNZ4CFKBe40b3MpGnOy7vWNwgAaIDWnqnKWf8mfHH2_fJymWEkZYkjHRidDFxgkQQW5hiPAVWPjLsGHaj08rZmDs_MuzeGHbhq_-mrm1Qe82a314Z5tufISVvFuzP7M7bSfKaeJM2H-Opz3_iHwKe4qdb7oX82FnDYHyI_xhKmNxqNSgCTycre9KwqZV3Xc4zLUrdlq3MSBRHbA4VL-oim0R5rNth0DVXpZSlbpqmR0LiiBz7vsXMCORYFbzgvE5GzlVR8aFSsmya46E9sIrTLI3NrT3PqY2ZCWElURTFsa0yKxXZsK0oYp8mwxDTtnqREh7UOgZWcWtCDH9LRBMtiXf9t4nuStOGQhJ234Zs9VZ8mqyJ06ry3s0Mu1R5Px5O3v2kPjLsNqaBYbeTPQv8HQAA___-PgQ8">