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

            Bug ID: 103774
           Summary: [i386] GCC should swap the arguments to certain
                    functions to generate a single instruction
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

I don't know how widespread this is. Seen in the code generated at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103750.

This code:
        __m256i data1 = _mm256_loadu_si256(reinterpret_cast<const __m256i
*>(n));
        __m256i data2 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(n)
+ 1);
        __mmask16 mask1 = _mm256_cmpeq_epu16_mask(data1, mch256);
        __mmask16 mask2 = _mm256_cmpeq_epu16_mask(data2, mch256);
Generates:
        vmovdqu16       (%rdi), %ymm1
        vmovdqu16       32(%rdi), %ymm2
        vpcmpuw $0, %ymm0, %ymm1, %k0
        vpcmpuw $0, %ymm0, %ymm2, %k1

While if you invert the two operands in the cmpeq intrinsics, as in:
        __m256i data1 = _mm256_loadu_si256(reinterpret_cast<const __m256i
*>(n));
        __m256i data2 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(n)
+ 1);
        __mmask16 mask1 = _mm256_cmpeq_epu16_mask(mch256, data1);
        __mmask16 mask2 = _mm256_cmpeq_epu16_mask(mch256, data2);
You get:
        vpcmpuw $0, (%rdi), %ymm0, %k0
        vpcmpuw $0, 32(%rdi), %ymm0, %k1


Godbolt link with full copileable source code:
https://gcc.godbolt.org/z/rKo666MM7

Clang, ICC (Clang-based) do this. MSVC behaves like GCC.

Reply via email to