Issue 98346
Summary Non-overlapping shuffle indices could use the same constant
Labels new issue
Assignees
Reporter dzaima
    For the following code:
```c
#include<immintrin.h>

__m256i unzip_i8(__m256i x1, __m256i x2) {
  __m256i idxs = _mm256_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14);
  __m256i a1 = _mm256_shuffle_epi8(x1, idxs);
  __m256i a2 = _mm256_shuffle_epi8(x2, idxs);
  return _mm256_permute4x64_pd(_mm256_blend_pd(a1, a2, 10), 216);
}
```
`-O3 -march=haswell` generates:
```asm
foo: # @foo
        vpshufb ymm1, ymm1, ymmword ptr [rip + .LCPI0_0] # ymm1 = ymm1[u,u,u,u,u,u,u,u,0,2,4,6,8,10,12,14,u,u,u,u,u,u,u,u,16,18,20,22,24,26,28,30]
 vpshufb ymm0, ymm0, ymmword ptr [rip + .LCPI0_1] # ymm0 = ymm0[0,2,4,6,8,10,12,14,u,u,u,u,u,u,u,u,16,18,20,22,24,26,28,30,u,u,u,u,u,u,u,u]
 vpblendd        ymm0, ymm0, ymm1, 204           # ymm0 = ymm0[0,1],ymm1[2,3],ymm0[4,5],ymm1[6,7]
        vpermq  ymm0, ymm0, 216 # ymm0 = ymm0[0,2,1,3]
        ret
```
despite those two shuffle index constants being non-overlapping (i.e. for any element, only one of the constants has a defined value) and thus could use the same load.

[Compiler explorer](https://godbolt.org/z/dz4r1fz8E)

```llvm
define dso_local <4 x i64> @foo(<4 x i64> noundef %x1, <4 x i64> noundef %x2) local_unnamed_addr {
entry:
  %0 = bitcast <4 x i64> %x1 to <32 x i8>
  %1 = bitcast <4 x i64> %x2 to <32 x i8>
  %2 = shufflevector <32 x i8> %0, <32 x i8> %1, <32 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 32, i32 34, i32 36, i32 38, i32 40, i32 42, i32 44, i32 46, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30, i32 48, i32 50, i32 52, i32 54, i32 56, i32 58, i32 60, i32 62>
 %blend.uncasted = bitcast <32 x i8> %2 to <4 x i64>
  %3 = shufflevector <4 x i64> %blend.uncasted, <4 x i64> poison, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  ret <4 x i64> %3
}
```
([same op with `@llvm.vector.deinterleave2`](https://godbolt.org/z/djb3rsdjd), same issue)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to