diff mbox series

[v2] x86: Optimize load of const all 1s float vectors

Message ID CAMe9rOpkL9AQ=X_rUBxh_2YKzDA7Ot4-NPPEzvXYc4+-+hai_Q@mail.gmail.com
State New
Headers show
Series [v2] x86: Optimize load of const all 1s float vectors | expand

Commit Message

H.J. Lu Aug. 9, 2021, 3:23 p.m. UTC
On Sun, Aug 8, 2021 at 1:23 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Sat, Aug 7, 2021 at 4:41 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > Update vector_all_ones_operand to return true for const all 1s float
> > vectors.
> >
> > gcc/
> >
> >         PR target/101804
> >         * config/i386/predicates.md (vector_all_ones_operand): Return
> >         true for const all 1s float vectors.
> >
> > gcc/testsuite/
> >
> >         PR target/101804
> >         * gcc.target/i386/avx2-gather-2.c: Pass -march=skylake instead
> >         of "-mavx2 -mtune=skylake".  Scan vpcmpeqd.
>
> No, vector_all_ones_operand is intended to be integer minus-one. Use
> float_vector_all_ones_operand in a specific place, where it is needed.
>

Like this?

Comments

Uros Bizjak Aug. 9, 2021, 3:27 p.m. UTC | #1
On Mon, Aug 9, 2021 at 5:24 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Sun, Aug 8, 2021 at 1:23 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > On Sat, Aug 7, 2021 at 4:41 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > Update vector_all_ones_operand to return true for const all 1s float
> > > vectors.
> > >
> > > gcc/
> > >
> > >         PR target/101804
> > >         * config/i386/predicates.md (vector_all_ones_operand): Return
> > >         true for const all 1s float vectors.
> > >
> > > gcc/testsuite/
> > >
> > >         PR target/101804
> > >         * gcc.target/i386/avx2-gather-2.c: Pass -march=skylake instead
> > >         of "-mavx2 -mtune=skylake".  Scan vpcmpeqd.
> >
> > No, vector_all_ones_operand is intended to be integer minus-one. Use
> > float_vector_all_ones_operand in a specific place, where it is needed.
> >
>
> Like this?

Please also add a new constraint, BC is intended for integer values.

Uros.
diff mbox series

Patch

From 017dee0c9ee946e16fbb1b938c1dd62ac0f95b09 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 6 Aug 2021 12:32:01 -0700
Subject: [PATCH v2] x86: Optimize load of const all 1s float vectors

Check float_vector_all_ones_operand for vector floating-point modes to
optimize load of const all 1s float vectors.

gcc/

	PR target/101804
	* config/i386/constraints.md (BC): For vector floating-point
	modes, also check float_vector_all_ones_operand.
	* config/i386/i386.c (standard_sse_constant_p): Likewise.
	(standard_sse_constant_opcode): Likewise.

gcc/testsuite/

	PR target/101804
	* gcc.target/i386/avx2-gather-2.c: Pass -march=skylake instead
	of "-mavx2 -mtune=skylake".  Scan vpcmpeqd.
---
 gcc/config/i386/constraints.md                |  4 +++-
 gcc/config/i386/i386.c                        | 11 +++++++++--
 gcc/testsuite/gcc.target/i386/avx2-gather-2.c |  3 ++-
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md
index 4aa28a5621c..cb1a803ab87 100644
--- a/gcc/config/i386/constraints.md
+++ b/gcc/config/i386/constraints.md
@@ -219,7 +219,9 @@  (define_constraint "BC"
   "@internal SSE constant -1 operand."
   (and (match_test "TARGET_SSE")
        (ior (match_test "op == constm1_rtx")
-	    (match_operand 0 "vector_all_ones_operand"))))
+	    (match_operand 0 "vector_all_ones_operand")
+	    (and (match_test "GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT")
+		 (match_operand 0 "float_vector_all_ones_operand")))))
 
 ;; Integer constant constraints.
 (define_constraint "Wb"
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index aea224ab235..4d4ab6a03d6 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -5073,7 +5073,11 @@  standard_sse_constant_p (rtx x, machine_mode pred_mode)
   if (x == const0_rtx || const0_operand (x, mode))
     return 1;
 
-  if (x == constm1_rtx || vector_all_ones_operand (x, mode))
+  if (x == constm1_rtx
+      || vector_all_ones_operand (x, mode)
+      || ((GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
+	   || GET_MODE_CLASS (pred_mode) == MODE_VECTOR_FLOAT)
+	  && float_vector_all_ones_operand (x, mode)))
     {
       /* VOIDmode integer constant, get mode from the predicate.  */
       if (mode == VOIDmode)
@@ -5171,7 +5175,10 @@  standard_sse_constant_opcode (rtx_insn *insn, rtx *operands)
 	  gcc_unreachable ();
 	}
     }
-  else if (x == constm1_rtx || vector_all_ones_operand (x, mode))
+  else if (x == constm1_rtx
+	   || vector_all_ones_operand (x, mode)
+	   || (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
+	       && float_vector_all_ones_operand (x, mode)))
     {
       enum attr_mode insn_mode = get_attr_mode (insn);
       
diff --git a/gcc/testsuite/gcc.target/i386/avx2-gather-2.c b/gcc/testsuite/gcc.target/i386/avx2-gather-2.c
index 1a704afd834..ad5ef73107c 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-gather-2.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-gather-2.c
@@ -1,6 +1,7 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mavx2 -fdump-tree-vect-details -mtune=skylake" } */
+/* { dg-options "-O3 -fdump-tree-vect-details -march=skylake" } */
 
 #include "avx2-gather-1.c"
 
 /* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 16 "vect" } } */
+/* { dg-final { scan-assembler "vpcmpeqd" } } */
-- 
2.31.1