<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62450>62450</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
manual popcnt has unnecessary cmove since clang 16.0.0
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
y21
</td>
</tr>
</table>
<pre>
Code:
```c
int popcnt(int x) {
int cnt = 0;
while (x) {
cnt++;
x &= x - 1;
}
return cnt;
}
```
On x86-64 clang 16.0.0 as well as trunk (17.0.0 d7fa92126cc398b993f301273816739b23ed8740) with `-O -march=haswell` compiles to:
```asm
popcnt: # @popcnt
popcnt eax, edi
cmove eax, edi
ret
```
(Note the unnecessary cmove)
On clang 15.0.0 with the same options:
```asm
popcnt: # @popcnt
popcnt eax, edi
ret
```
[Reproducer](https://godbolt.org/z/fbMEvxjKd)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8k09v4ywQxj_N-DJKhAf_4-BD07y5vNqttN8A40nsLjaRwW26n36FnabbdntdhEDD8DwMPxvtfX8amWvId5DvEz2Hzk31C6VJ49qX-t61DPIOxB7EHRRi7WaN-zHg2Z3NGICqGFyAFEK5W9OIiHHVjAFB7lGA_CPz3PWWEaj6LIptMd3FfhNdEKiIRhfcYPrODMr9WzBxmKdxcXjdc8vfrnANl_FhxEtVbIoMjdXjCdNiK7YCtcdntjbOYZrHn7HYtFxSbXnUilIqjJGqapSSRylSKmWVFqVUDUluqzIT8WrPfegQCrF5wM2gJ9OB3HfaR2soBBo3nHvLHoP7DFr7YV25YpY3Pl82IImQiatghbIGiKwvQPfIbf8B9uCeGL_OTxz-jo-q7y4who5xHkc27L2eXlY_IPUB8pVuviBcsESh1wOjO4fejf7fE_jyauuY737weXLtbHiCfA9UdSGclzrpAHQ4ubZxNmzddAI6_AI6HJtv_z1dHv9vgVTS1rJVUumE67SoqCxUnpdJVxs6VtkxFa3Ipc7L3LRSGVkZjj9QJpqkr0mQFBmpNM1VWm6VyLg6ptSosiwpI8gED7q3W2ufhnh80ns_c11QlovE6oatf33UUx03bZr55CETtvfBv8lCHyzXgx5nbV8xddp__p7o-9HwuyeSzJOtPwDpQzc3W-MGoEM85DptzpN7ZBOADkuhHuiw1Po7AAD__70fPAE">