This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Optimize %k register comparison against zero (PR target/82855)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Uros Bizjak <ubizjak at gmail dot com>, Kirill Yukhin <kirill dot yukhin at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 6 Nov 2017 22:23:24 +0100
- Subject: [PATCH] Optimize %k register comparison against zero (PR target/82855)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 70EFBBDFD
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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 <jakub@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>")
+ (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