<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69338>69338</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization: excessive register zeroing
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dvyukov
</td>
</tr>
</table>
<pre>
```
void foo(unsigned* dst, const unsigned* src, unsigned size) {
unsigned idx1 = size > 16 ? 1 : 0;
dst[idx1] = src[idx1];
unsigned idx2 = size > 24 ? 2 : 0;
dst[idx2] = src[idx2];
}
```
[clang generates](https://godbolt.org/z/GErr3Tox4):
```
xor eax,eax
cmp edx,0x11
setae al
mov ecx,DWORD PTR [rsi+rax*4]
mov DWORD PTR [rdi+rax*4],ecx
xor eax,eax
cmp edx,0x19
setae al
mov ecx,DWORD PTR [rsi+rax*8]
mov DWORD PTR [rdi+rax*8],ecx
ret
```
The second `xor eax,eax` is excessive: high bytes are already zero.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUU9FumzAU_ZrLy1UjY2MCDzwkTdnTtKmqtGfHvgNvBEe2yZJ8_WSaNU23VaqEDJx7zvG5cK1CsN1I1IBcg9xkaoq98405nKaf7pBtnTk1ULLLxTbAVgdnDX53Dng1jbPaAF-hCRH4PWo3hoivC8HrVPgDYbBnAl4jLNfPhsDql6I1xxxBbGYWgnjAvEQQLSZ0hQzEVZR2lOukALl5Fnl9RV5TX_vzW39ezP78HX_-lz-_8V9uLg-3H-qyyrUe1NhhRyN5FSkkLa_6GPcBxAp4C7ztnNm6IS6c74C3Z-DtpwfvxZM7FsDrRPvXDnh0HhGR1BH4fVqfYb3bz7BJMDvm-QUPFBUhquHyvnOHmacTb_Pty-MGvz49Isi1Dxb42iffVZECXwW3PPOGx--T24fS1TfpPhiuug2H-P981dt8nuI7P-6pJwyk3WgQSpZ6uTZSMrQB6agpBHugNDq97XrcniIFVD614UmZE57Ju0VmGmFqUauMmrysl1IKUYisb6pKkC6YZErny7w2TDOdlyaXRcJlkdmGMy5yli_zQshCLDRVphJlVUjBhJEMCkY7ZYfFMBx2aXwyG8JETVkLUWWD2tIQ5sPN-Ui_cC4CT_Ob-SZp7rZTF6Bggw0xXF2ijQM1n20IZNDto93Zs4rWjanXl8bRU2dDJD_3accum_zQvBltG_tpu9BuB7xN_pfb3d67H6Qj8HZOFYC3c-rfAQAA__8fXFFZ">