<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116977>116977</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unnecessary conversion of `(a==v)&(b==v)` into `(a!=v)|(b!=v)` results in more assembly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dzaima
</td>
</tr>
</table>
<pre>
The code:
```c
#include <immintrin.h>
_Bool both_equal(__m256i a, __m256i b, __m256i v) {
__m256i a1 = _mm256_cmpeq_epi8(v, a);
__m256i b1 = _mm256_cmpeq_epi8(v, b);
__m256i all = _mm256_and_si256(a1, b1);
return _mm256_movemask_epi8(all) == 0xFFFFFFFF;
}
```
compiled with `-O3 -march=haswell` on clang 19.1 or trunk gives:
```asm
both_equal:
vpcmpeqb ymm0, ymm2, ymm0
vpcmpeqd ymm3, ymm3, ymm3
vpxor ymm0, ymm0, ymm3
vpcmpeqb ymm1, ymm2, ymm1
vpxor ymm1, ymm1, ymm3
vpor ymm0, ymm0, ymm1
vpmovmskb eax, ymm0
test eax, eax
sete al
vzeroupper
ret
```
whereas 18.1 produced the better:
```asm
both_equal:
vpxor ymm0, ymm0, ymm2
vpxor ymm1, ymm1, ymm2
vpor ymm0, ymm0, ymm1
vptest ymm0, ymm0
sete al
vzeroupper
ret
```
https://godbolt.org/z/coK5qqErr (variant with 4 tests instead of 2: https://godbolt.org/z/96eEK439G)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVMtyqzgQ_RqxUcUlNZjHgkUSx7O4i9nMrF0NdIwmEiKSII-vnwLsxI-kcq_KVapunXNonbYavVf7jqhk6zu23kQ4hNa6snlHZTCqbPNW_tMSr21DLL5lYsPELUvF8qsPMcSqq_XQEGfxvTJGdcGpbtWy-GFB7O6s1byyod3R84CaQb7bGViniiODe34MqtNgZFBwlt0tEh9plJzFG74zU7irTU_PO-pVziAfJzoyKFh8ZH1K_0Crvqah1qc87JqdV7BOGeQoZ548JzoKg-uOeGNHMuifjp9CredbxZtJVLxuD-tDgGWbC5OXsLamV5oa_qJCy1kqbv6O-Y1BV7cs3rToX0hrlgpuO15r7PZcFivJrePBDd0T36uR_HUH0Zslc9KbI4iP_WxTxQ_rzRgxXfnNGDjs4njtZR0YzQkjPiA_9wvGq3Xn2uI75FU18qIa-a22_EB8oz0Dv6riStPY0finYxmEr19bEciHE8C0LeeeAk0HqC-U38nZoe_JnecdhS__ES8tOULPZb6SvHe2GWpqeGiJVxQCuT9s9s_9gN929wr5--4utp0hzxBX7v2pbW0I_fwQYMtgu7dNZXVYWbdnsH1nsK3tr_Xz84NzfJoM6BR2YXl0ydxTz1XnA2HD7SMHFt_ynxSLlB5-JXHxF4Miasq4KeICIyplFoOUILIiassKq8c11rLGrKFcJIgAFdGaRFGlj1RFqgQByYSXiUzifJUi5qnIHvMkbzLMkCWCDCq90no00-cj5f1ApZRpkWWRxoq0n8c8QEcvfD5lANPUd-VEuqmGvWeJ0MoH_ykTVNBU_tt1VJP36N54bbuRnFe2m0yYrIUcl5k2DW0G03isThKp4KoL9gMK8niS3c_Qz0QquCM_6Nlobqwjjt6TqfRbNDhdXritQjtUq9oaBtup4sN20zv7H9WBwXa-p2ewPRgxlvB_AAAA__8Hf_hP">