https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128233

            Bug ID: 128233
           Summary: Missed elimination of AVX2 gather mask copy when
                    bitcast follows empty inline asm.
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: z00823823 at outlook dot com
  Target Milestone: ---

online version: https://godbolt.org/z/TKo18Eh9f

```c++
#include <immintrin.h>

extern "C" __m256d cast_after(const double* base, __m256i index) {
    __m256i mask = _mm256_set1_epi32(-1);
    asm("" : "+x"(mask));
    return _mm256_mask_i64gather_pd(
        _mm256_setzero_pd(), base, index, _mm256_castsi256_pd(mask), 8);
}

extern "C" __m256d cast_before(const double* base, __m256i index) {
    __m256d mask = _mm256_castsi256_pd(_mm256_set1_epi32(-1));
    asm("" : "+x"(mask));
    return _mm256_mask_i64gather_pd(
        _mm256_setzero_pd(), base, index, mask, 8);
} 
```

result:

```asm
"cast_after":
        vmovdqa ymm2, ymm0
        vpcmpeqd        ymm3, ymm3, ymm3
        vxorpd  xmm0, xmm0, xmm0
        vmovapd ymm1, ymm3
        vgatherqpd      ymm0, QWORD PTR [rdi+ymm2*8], ymm1
        ret
"cast_before":
        vmovdqa ymm2, ymm0
        vxorpd  xmm0, xmm0, xmm0
        vpcmpeqd        ymm1, ymm1, ymm1
        vgatherqpd      ymm0, QWORD PTR [rdi+ymm2*8], ymm1
        ret
```

when I do type cast after an empty inline asm, gcc added an extra `vmovapd
ymm1, ymm3`, but the cast just reinterpret bits so this vmpvapd should be
elimimated.

Reply via email to