<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/157131>157131</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[X86] Poor code generation for boolean vectors on AVX2
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jhuber6
</td>
</tr>
</table>
<pre>
Boolean vectors are often lowered to integral operations. This code generates the expected bitwise operations only when `avx512f` is available even though it does not require use of mask registers https://clang.godbolt.org/z/vrdbo9YKa.
```c++
#include <cstdint>
typedef __attribute__((ext_vector_type(16))) int16_t i16x16;
typedef __attribute__((ext_vector_type(16))) bool i1x16;
int A(i16x16);
void test(i16x16 v, i1x16 a, i1x16 b) {
i1x16 m = (a & (~b)) != 0;
if (__builtin_reduce_or(m))
A(v);
}
```
This is introduced at the first instruction selection phase, so I am guessing that lowering these is trying to use the mask registers which then get optimized away.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVD2P4zYQ_TWjZnCGRFlfhQrvbQwEaVIEwaUSSHEs8Y4mHXIkr6_Ibw8oGbd7aWMMYJIz7_GRekMZo5kcUQ_VC1SvmVx49qH_Oi-KQp0prx_9i_eWpMOVRvYhogyE_sLk0Po7BdLIHo1jmoK06G8UJBvv4gH_mE3E0WvCiVxapog8E9LbjUYmjcrw3UT6AELv7APvMzmEOpfrW1WIC9Q5mohylcZKZQlpJYc8-2Wa0TBqTxGdZwz092IC4ZI4L3iV8RsGmkxkChFn5luE8gTiDOI8Wummw-S18pYPPkwgzt9BnNegle_--k0eID-lqPM9RhAvKfITiNK40S6aEMrPY2RtHEP5yw7gx400XXAYJHMwamEaBhAtiJbeeNivcUhVINqiBtHtke6wqAdGU9RvRQ3ly_8hU95bNMUPIshPxjGeQLRPftH9yKzeaGSK_COLK4jPOx7l-1AlamgSDBGfi1eE8hVBtBJB1Gnwj3qqAFGkXL7vtEEuqWAY1GIsGzcE0stIgw8g2utT_l6Zfknu-q60ef34QXbtm8lSOA4-cWmUvNnsYkJkNC5yWMbkLoxkaR_dZhkpnSt6_BXlFaeFYjRuQp4l787eZxQp0XN4bHO_mSvR_8dd99mMc0o4nIjR39hczfek5i4fh0z3pe7KTmbUF03V5G1T1V0299XxKOqmVJdajE2p8rHUpKq2ItEdu7w8ZqYXuajyLq-KqhLH7lA0dVXXpapE1yjdFnDM6SqNPVi7XpORMxPjQn1RNUVZZFYqsnFrcCGUHL-R01CevrQ1CJF6PvQJ-EktU4Rjbk3k-E7Fhu32OqT66hV_9z781NLpMi8-bH77-Ep4h6c_v4hsCbb_ufEmw_OiDqO_gjinjZ5_n27Bf6WRQZy3A0QQ5-cZ1l78GwAA__8Bq3kL">