On Mon, Nov 6, 2017 at 10:23 PM, Jakub Jelinek <ja...@redhat.com> wrote: > Hi! > > Without the following patch we emit kmovb %k1, %eax; testb %al, %al > when if just testing the Zero bit we can as well do ktestb %k1, %k1. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2017-11-06 Jakub Jelinek <ja...@redhat.com> > > PR target/82855 > * config/i386/i386.md (SWI1248_AVX512BWDQ2_64): New mode iterator. > (*cmp<mode>_ccz_1): New insn with k alternative. > > * gcc.target/i386/avx512dq-pr82855.c: New test. > > --- gcc/config/i386/i386.md.jj 2017-10-28 09:00:44.000000000 +0200 > +++ gcc/config/i386/i386.md 2017-11-06 12:57:44.171215745 +0100 > @@ -1275,6 +1275,26 @@ (define_expand "cmp<mode>_1" > (compare:CC (match_operand:SWI48 0 "nonimmediate_operand") > (match_operand:SWI48 1 "<general_operand>")))]) > > +(define_mode_iterator SWI1248_AVX512BWDQ2_64 > + [(QI "TARGET_AVX512DQ") (HI "TARGET_AVX512DQ") > + (SI "TARGET_AVX512BW") (DI "TARGET_AVX512BW && TARGET_64BIT")]) > + > +(define_insn "*cmp<mode>_ccz_1" > + [(set (reg FLAGS_REG) > + (compare (match_operand:SWI1248_AVX512BWDQ2_64 0 > + "nonimmediate_operand" "<r>,k,?m<r>")
Please put "k" alternative as the last alternative. I suggest to decorate it with "*", so register allocator won't use mask registers instead of integer registers. This would be the same solution as in movdi_internal/movsi_internal patterns. Uros. > + (match_operand:SWI1248_AVX512BWDQ2_64 1 "const0_operand")))] > + "ix86_match_ccmode (insn, CCZmode)" > + "@ > + test{<imodesuffix>}\t%0, %0 > + ktest<mskmodesuffix>\t%0, %0 > + cmp{<imodesuffix>}\t{%1, %0|%0, %1}" > + [(set_attr "type" "test,msklog,icmp") > + (set_attr "length_immediate" "0,*,1") > + (set_attr "modrm_class" "op0,*,unknown") > + (set_attr "prefix" "*,vex,*") > + (set_attr "mode" "<MODE>")]) > + > (define_insn "*cmp<mode>_ccno_1" > [(set (reg FLAGS_REG) > (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>,?m<r>") > --- gcc/testsuite/gcc.target/i386/avx512dq-pr82855.c.jj 2017-11-06 > 13:51:21.380463119 +0100 > +++ gcc/testsuite/gcc.target/i386/avx512dq-pr82855.c 2017-11-06 > 13:52:07.164875064 +0100 > @@ -0,0 +1,14 @@ > +/* PR target/82855 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -mavx512vl -mavx512dq" } */ > +/* { dg-final { scan-assembler {\mktestb\M} } } */ > + > +#include <immintrin.h> > + > +int > +foo (const __m256i *ptr) > +{ > + __m256i v = _mm256_loadu_si256 (ptr); > + __mmask8 m = _mm256_cmpeq_epi32_mask (v, _mm256_setzero_si256 ()); > + return 0 == m; > +} > > Jakub