https://llvm.org/bugs/show_bug.cgi?id=28839

            Bug ID: 28839
           Summary: AVX512: Register allocator doesn't understand mask
                    registers
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedb...@nondot.org
          Reporter: wenzel.ja...@epfl.ch
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

The LLVM register allocator fails to effectively deal with mask registers and
sometimes generates bizarre sequences of moves from mask to integer registers
(and back!).

Consider the following code fragment compiled with the HEAD revision of
LLVM/Clang:

#include <immintrin.h>

__mmask16 combine(__m512 a, __m512 b, __m512 c, __m512 d, __m512 x) {
    __mmask16 m1 = _mm512_cmp_ps_mask(a, x, _CMP_GE_OS);
    __mmask16 m2 = _mm512_cmp_ps_mask(b, x, _CMP_GE_OS);
    __mmask16 m3 = _mm512_cmp_ps_mask(c, x, _CMP_GE_OS);
    __mmask16 m4 = _mm512_cmp_ps_mask(d, x, _CMP_GE_OS);

    return _mm512_kor(_mm512_kor(m1, m2), _mm512_kor(m3, m4));
}

This is what I get (clang++ -mavx512f test.cpp -o test.s -O3 -S
-fomit-frame-pointer):

__Z7combineDv16_fS_S_S_S_:              ## @_Z7combineDv16_fS_S_S_S_
    vcmpgeps    %zmm4, %zmm0, %k0
    kmovw    %k0, %eax
    vcmpgeps    %zmm4, %zmm1, %k0
    kmovw    %k0, %ecx
    vcmpgeps    %zmm4, %zmm2, %k0
    kmovw    %k0, %edx
    vcmpgeps    %zmm4, %zmm3, %k0
    kmovw    %k0, %esi
    kmovw    %ecx, %k0
    kmovw    %eax, %k1
    korw    %k0, %k1, %k0
    kmovw    %esi, %k1
    kmovw    %edx, %k2
    korw    %k1, %k2, %k1
    korw    %k1, %k0, %k0
    kmovw    %k0, %eax
    movzwl    %ax, %eax
    retq


Note all the unnecessary 'kmov' instructions, and that vcmpgeps only seems to
be able to put its output into the 'k0' register.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to