public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-338] i386: Add combine splitter to transform pxor/pcmpeqb/pmovmskb/cmp 0xffff to ptest.
@ 2022-05-12  9:37 Hongyu Wang
  0 siblings, 0 replies; only message in thread
From: Hongyu Wang @ 2022-05-12  9:37 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3c9364f29e7e47eb9de33f2d8843d5b00284ceca

commit r13-338-g3c9364f29e7e47eb9de33f2d8843d5b00284ceca
Author: Haochen Jiang <haochen.jiang@intel.com>
Date:   Tue Feb 8 10:51:26 2022 +0800

    i386: Add combine splitter to transform pxor/pcmpeqb/pmovmskb/cmp 0xffff to ptest.
    
    gcc/ChangeLog:
    
            PR target/104371
            * config/i386/sse.md (vi1avx2const): New define_mode_attr.
            (pxor/pcmpeqb/pmovmskb/cmp 0xffff to ptest splitter):
            New define_split pattern.
    
    gcc/testsuite/ChangeLog:
    
            PR target/104371
            * gcc.target/i386/pr104371-1.c: New test.
            * gcc.target/i386/pr104371-2.c: Ditto.

Diff:
---
 gcc/config/i386/sse.md                     | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/i386/pr104371-1.c | 13 +++++++++++++
 gcc/testsuite/gcc.target/i386/pr104371-2.c | 13 +++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index a63df0d0b1f..6578104fee2 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -20177,6 +20177,24 @@
    (set_attr "prefix" "maybe_vex")
    (set_attr "mode" "SI")])
 
+;; Optimize pxor/pcmpeqb/pmovmskb/cmp 0xffff to ptest.
+(define_mode_attr vi1avx2const
+  [(V32QI "0xffffffff") (V16QI "0xffff")])
+
+(define_split
+  [(set (reg:CCZ FLAGS_REG)
+	(compare:CCZ (unspec:SI
+			[(eq:VI1_AVX2
+			    (match_operand:VI1_AVX2 0 "vector_operand")
+			    (match_operand:VI1_AVX2 1 "const0_operand"))]
+		    UNSPEC_MOVMSK)
+		 (match_operand 2 "const_int_operand")))]
+  "TARGET_SSE4_1 && (INTVAL (operands[2]) == (int) (<vi1avx2const>))"
+  [(set (reg:CC FLAGS_REG)
+	(unspec:CC [(match_dup 0)
+		    (match_dup 0)]
+		   UNSPEC_PTEST))])
+
 (define_expand "sse2_maskmovdqu"
   [(set (match_operand:V16QI 0 "memory_operand")
 	(unspec:V16QI [(match_operand:V16QI 1 "register_operand")
diff --git a/gcc/testsuite/gcc.target/i386/pr104371-1.c b/gcc/testsuite/gcc.target/i386/pr104371-1.c
new file mode 100644
index 00000000000..b4373c55ab2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr104371-1.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -msse4" } */
+/* { dg-final { scan-assembler "ptest\[ \\t\]" } } */
+/* { dg-final { scan-assembler-not "pxor\[ \\t\]" } } */
+/* { dg-final { scan-assembler-not "pcmpeqb\[ \\t\]" } } */
+/* { dg-final { scan-assembler-not "pmovmskb\[ \\t\]" } } */
+
+#include <smmintrin.h>
+
+int is_zero(__m128i x)
+{
+  return _mm_movemask_epi8(_mm_cmpeq_epi8(x, _mm_setzero_si128())) == 0xffff;
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr104371-2.c b/gcc/testsuite/gcc.target/i386/pr104371-2.c
new file mode 100755
index 00000000000..3431ffc1cc2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr104371-2.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx2" } */
+/* { dg-final { scan-assembler "vptest\[ \\t\]" } } */
+/* { dg-final { scan-assembler-not "vpxor\[ \\t\]" } } */
+/* { dg-final { scan-assembler-not "vpcmpeqb\[ \\t\]" } } */
+/* { dg-final { scan-assembler-not "vpmovmskb\[ \\t\]" } } */
+
+#include <immintrin.h>
+
+int is_zero256(__m256i x)
+{
+  return _mm256_movemask_epi8(_mm256_cmpeq_epi8(x, _mm256_setzero_si256())) == 0xffffffff;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-12  9:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12  9:37 [gcc r13-338] i386: Add combine splitter to transform pxor/pcmpeqb/pmovmskb/cmp 0xffff to ptest Hongyu Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).