<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96463>96463</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
x86 SSE4.2 suboptimal codegen: `_mm_cmpestrc` is not fused with `_mm_cmpestri` or `_mm_cmpestrm`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
AlexGuteniev
</td>
</tr>
</table>
<pre>
The following C++ code:
```c++
#include <immintrin.h>
int test1(__m128i needle, __m128i haystack) {
if (_mm_cmpestrc(needle, 2, haystack, 8, _SIDD_CMP_EQUAL_ORDERED | _SIDD_BIT_MASK))
{
int bitmask = _mm_cmpestri(needle, 2, haystack, 8, _SIDD_CMP_EQUAL_ORDERED | _SIDD_BIT_MASK);
return bitmask;
}
else
{
return 0;
}
}
int test2(__m128i needle, __m128i haystack) {
if (_mm_cmpestrc(needle, 2, haystack, 8, _SIDD_CMP_EQUAL_ORDERED | _SIDD_BIT_MASK))
{
int bitmask = _mm_cvtsi128_si32(_mm_cmpestrm(needle, 2, haystack, 8, _SIDD_CMP_EQUAL_ORDERED | _SIDD_BIT_MASK));
return bitmask;
}
else
{
return 0;
}
}
```
Produces two `pcmpestri` instructions for `test1` and `pcmpestri` followed by `pcmpestrm` for test2`,
Demo: https://godbolt.org/z/GE783h8dz
I expect that `_mm_cmpestrc` is fused with the other intrinsic, so there's one `pcmpestri` in `test1` and one `pcmpestrm` for test2.
(MSVC does this susion for `test1`, and gcc does this fusion for both `test1` and `test2`)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVVuv4jYQ_jXOy2iRMwm5POSBQ2B11B51u2z7ihJ7IO46Noqdc9lfX5nAAmfpW6tKK0UBZS7fN_ONx41zam-IKjZ_YPM6akbf2aFaaHr9OHoyip6j1sq36ktHsLNa2xdl9rBk-MDwAYSVxJIF4zXj53fGp0dMPqevmCgj9CgJWLJUfa-MH5SZdSxZXUcr48GT8zHDYrvtYywUGCKpieESzl-65s35RnxlWALLzxC8VDsIcX2_Ff2BnB8Ew-ISjuF1iV1CcUy6eazr7fLp03b1-x-LX7e_fa5Xn1c1sPxse3j8sn1abH5hWIbnjHaNHMCNh1b5vnFfgSU1XNFQ_zqN5AZ6ID8O5ox-Y8zr7_9JO_on8qcM_H5sXsM9kfAnEenZOxVjsXUqwVtq_X9B7f_S7nwwr6X8NFg5CnLgXyywjB--T2zGQRnnh1F4ZY2DnR2Cw3Q4Mw6NkT8ETAuCJLRv17Z-sg2nock4w-UEX1NvWbKAzvuDC4sE1wzXeytbq_3MDnuG628M1x9XeZF0hfx2zf0R6PVAwoPvGh_wbmYq8HewGx1JeFG-A98RWN_RANPucUoE-ZwNloEY5g6soTtd-KHud2639c3OG6942vy5BGlDdzvlwI1OWfO-kYFDyLkX4sp3d_Ftre_udf7SzDKSVSLLpGwiquI8LjEu0jiPuiop5mlC1FLeJFjwuZjHcS7nuZwTNijaSFXIMeUZprxIeZzP8gRbpBZ5LKQQsmQpp75Reqb1cx8UiZRzI1VllmZJpJuWtDteHoiGXuBoZIjhLhmqEPOhHfeOpVwr590li1deU_VaZLDZrNIZghtbe_Cqb_TxVtmTCYNxX1Vj_bWyt05H0aYe35zkjEfjoKt3o6Z8N7YzYXuG60Du9PPhMNi_SHiG62NJjuF6Kvm5wr8DAAD__5g5IDc">