https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128709
--- Comment #6 from Zoltan Hidvegi <zoltan at hidvegi dot com> ---
The shuffle implementation I've suggested is wrong, here is the working
version, it's a bit more code, but still better than __builtin_shuffle:
__m256i shuffle_epi8_avx2(__m256i v, __m256i p)
{
const __m256i lomask = (__m256i)(__v4di){-1,-1};
__m256i sel = _mm256_slli_epi16(p ^ lomask, 3);
p &= _mm256_set1_epi8(0x0F);
__m256i swapped = _mm256_permute4x64_epi64(v, 0x4E);
__m256i same = _mm256_shuffle_epi8(v, idx);
__m256i other = _mm256_shuffle_epi8(swapped, idx);
return _mm256_blendv_epi8(other, same, sel);
}