AVX512: Register allocator doesn't understand mask registers
| Bugzilla Link | 28839 |
| Resolution | FIXED |
| Resolved on | Aug 07, 2016 09:00 |
| Version | trunk |
| OS | All |
| CC | @delena,@hfinkel,@igor-breger |
Extended Description
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.
Fixed in 277958.