<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55158>55158</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
AVX1 vs AVX2 miscompilation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86,
miscompilation
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RKSimon
</td>
</tr>
</table>
<pre>
Reported here: https://twitter.com/benjinsmith/status/1519129265744367616
```
#include <immintrin.h>
__m128i do_stuff(const int* iVals) {
__m128i var_142 = _mm_load_si128((const __m128i*)&iVals[0]);
__m128i var_137 = _mm_load_si128((const __m128i*)&iVals[16]);
__m128i var_136 = _mm_load_si128((const __m128i*)&iVals[32]);
__m128i var_122 = _mm_cvtepi8_epi32(var_142);
__m128i var_76 = _mm_cmplt_epi32(var_122, var_136);
__m128i var_69 = _mm_hsub_epi16(var_137, var_137);
__m128i var_54 = _mm_cvtepu32_epi64(var_76);
__m128i var_34 = {};
__m128i var_22 = _mm_cmpeq_epi8(var_34, var_69);
__m128i var_13 = _mm_cmpeq_epi8(var_34, var_22);
__m128i var_6 = _mm_cvtepu8_epi64(var_13);
__m128i var_3 = _mm_insert_epi64(var_6, 0, 1);
__m128i var_1 = _mm_srlv_epi64(var_3, var_54);
__m128i var_0 = _mm_unpackhi_epi64(var_1, var_69);
return var_0;
}
```
clang -O1 -march=ivybridge -mavx2
```
do_stuff(int const*): # @do_stuff(int const*)
vmovdqa 64(%rdi), %xmm0
vmovdqa 128(%rdi), %xmm1
vpmovsxbd (%rdi), %xmm2
vpcmpgtd %xmm2, %xmm1, %xmm1
vphsubw %xmm0, %xmm0, %xmm0
vpmovzxdq %xmm1, %xmm1 # xmm1 = xmm1[0],zero,xmm1[1],zero
vpxor %xmm2, %xmm2, %xmm2
vpsrlvq %xmm1, %xmm2, %xmm1
vpunpckhqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[1],xmm0[1]
retq
```
clang -O1 -march=haswell -mavx2
```
do_stuff(int const*): # @do_stuff(int const*)
vmovdqa 64(%rdi), %xmm0
vpmovsxbd (%rdi), %xmm1
vmovdqa 128(%rdi), %xmm2
vphsubw %xmm0, %xmm0, %xmm0
vpcmpgtd %xmm1, %xmm2, %xmm1
vpmovzxdq %xmm1, %xmm1 # xmm1 = xmm1[0],zero,xmm1[1],zero
vpsrlvq %xmm1, %xmm0, %xmm1
vpunpckhqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[1],xmm0[1]
retq
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVlktvozAQgH8NuaBGfvA8cGib7WUPK3Wlam-RATe4ax6xDU3763cgkEAetOphtRuhgM3MNw_PGMdl-hY98qpUhqd2xhW36K2dGVNpeLDIA1zmVRjD1TIpcxjFvHgRhc6FyWCkDTO1hgfs4hCTkHiu7zjU8z3sWWhloVvLQ_21HxIqikTWKbctei_yXBRGiWKZWfTbXmK9zjEJhJ2Wa23q52eLBElZaGODpEVubfHEJFgMbcu_65koHJQaptbYIcBe2es8X8uSpWst4J3VXXtSLw004FjE2yPdO2S5q3aGXgFT_4tgSMYHZO-LZEo-IJNjMpLG8EoEa_gDNRL0yZrR9o9uJXklzVSVwNP94P8MxQsPlEzXcQuBhPQQ6h8h_gzEdaZx1JS0IM_pQf6cB3Sv3FaMv7omNM5UXvFtiw96OnUGL71wdh0_gyBzKfdOwgwmUWI6F-VBFRqUKzPR9FrrqP3DcwEcEFrJZgKgg_uuMwNAB0BdVCz5nYmp_1fTqLipVbFnHOdhtS7tIolkxca--YHtm5ypBDaPlWjeYiXSDW-nmh25qDfaU2A3sbvW6lsKtr1rP9izbMtBM8odfBBv8rJJt8zugraIq1LR9ew9gNxdnqPL4kPDn8njE_kKFPQuTg_eXVIip0pQjxsz6ByERkau22ub9vXg_CiOqyG1Lr7v0u3E2tjEaXq7ubZyOrlhJ75_56qEWz-JR5Mn9naluhQVmUlIW-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