Re: PING^1 [PATCH v4 0/2] x86: Convert CONST_WIDE_INT/CONST_VECTOR to broadcast

2021-06-26 Thread H.J. Lu via Gcc-patches
On Thu, Jun 24, 2021 at 11:04 PM Hongtao Liu  wrote:
>
> On Fri, Jun 25, 2021 at 2:01 PM Hongtao Liu  wrote:
> >
> > I didn't receive
> > https://gcc.gnu.org/pipermail/gcc-patches/2021-June/572436.html in my
> > gmail account, does anyone know why?
> >
> >
> > >--- a/gcc/config/i386/i386-protos.h
> > >+++ b/gcc/config/i386/i386-protos.h
> > >@@ -260,6 +260,7 @@ extern void ix86_expand_mul_widen_hilo (rtx, rtx, rtx, 
> > >bool, bool);
> > > extern void ix86_expand_sse2_mulv4si3 (rtx, rtx, rtx);
> > > extern void ix86_expand_sse2_mulvxdi3 (rtx, rtx, rtx);
> > > extern void ix86_expand_sse2_abs (rtx, rtx);
> > >+extern bool ix86_expand_integer_vec_duplicate (rtx *);
> > >
> > > /* In i386-c.c  */
> > > extern void ix86_target_macros (void);
> > >diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
> > >index 2a34756be2a..f094e5a2586 100644
> > >--- a/gcc/config/i386/sse.md
> > >+++ b/gcc/config/i386/sse.md
> > >@@ -24570,3 +24570,24 @@
> > >   "TARGET_WIDEKL"
> > >   "aes\t{%0}"
> > >   [(set_attr "type" "other")])
> > >+
> > >+;; Modes handled by broadcast patterns.
> > >+(define_mode_iterator INT_BROADCAST_MODE
> > >+  [(V64QI "TARGET_AVX512F") (V32QI "TARGET_AVX") V16QI
> > >+   (V32HI "TARGET_AVX512F") (V16HI "TARGET_AVX") V8HI
> > >+   (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX") V4SI
> > >+   (V8DI "TARGET_AVX512F && TARGET_64BIT")
> > >+   (V4DI "TARGET_AVX && TARGET_64BIT") (V2DI "TARGET_64BIT")])
> > TARGET_AVX512BW is needed for V64QI and V32HImode.

I will fix them.

> > And consider the scenario, TARGET_AVX2 is needed for all other
> > 128/256-bit modes?
>
> Actually we can use vbroadcastss/d for SI/DImode which means
> V2DI/V4DI/V8SI/4SI only need TARGET_AVX.
>
> (define_insn "vec_dup"
>   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "=x,x,x,v,x")
> (vec_duplicate:AVX_VEC_DUP_MODE
>   (match_operand: 1 "nonimmediate_operand"
> "m,m,x,v,?x")))]
>   "TARGET_AVX"
>
> I saw in patch 1/2 TARGET_AVX2 is also needed for every modes.

I will allow AVX with SI/DI broadcast.

> > >+
> > >+;; Broadcast from an integer.  NB: Enable broadcast only if we can move
> > >+;; from GPR to SSE register directly.
> > >+(define_expand "vec_duplicate"
> > >+  [(set (match_operand:INT_BROADCAST_MODE 0 "register_operand")
> > >+ (vec_duplicate:INT_BROADCAST_MODE
> > >+   (match_operand: 1 "general_operand")))]
> > >+  "TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC"
> > Why not directly use TARGET_AVX2 here, not in 
> > ix86_expand_integer_vec_duplicate.

We allow SSE2 for variable broadcast.

> > Also define some predicate to restrict operand[1] to be const_int but
> > not const0_rtx and constm1_rtx.
> > w/ this, guess there's no need for FAIL? and you can directly
> > call ix86_expand_vector_init_duplicate.

general_operand is used to allow both variable and constant broadcast
so that I can use vector broadcast in memset with both variable and constant.
Changing the predicate won't help SSE nor AVX for constant broadcast since
the expander will generate a sequence of codes to satisfy the
predicate.  If it is
allowed to FAIL, the memset expander can use load from constant pool for
SSE2 and AVX.

> > >+{
> > >+  if (!ix86_expand_integer_vec_duplicate (operands))
> > >+FAIL;
> > >+  DONE;
> > >
> >
> > On Fri, Jun 25, 2021 at 1:30 AM H.J. Lu via Gcc-patches
> >  wrote:
> > >
> > > On Wed, Jun 9, 2021 at 4:39 PM H.J. Lu  wrote:
> > > >
> > > > 1. Update move expanders to convert the CONST_WIDE_INT and CONST_VECTO
> > > > operands to vector broadcast from an integer with AVX2.
> > > > 2. Add ix86_gen_scratch_sse_rtx to return a scratch SSE register which
> > > > won't increase stack alignment requirement and blocks transformation by
> > > > the combine pass.
> > > >
> > > > A small benchmark:
> > > >
> > > > https://gitlab.com/x86-benchmarks/microbenchmark/-/tree/memset/broadcast
> > > >
> > > > shows that broadcast is a little bit faster on Intel Core i7-8559U:
> > > >
> > > > $ make
> > > > gcc -g -I. -O2   -c -o test.o test.c
> > > > gcc -g   -c -o memory.o memory.S
> > > > gcc -g   -c -o broadcast.o broadcast.S
> > > > gcc -g   -c -o vec_dup_sse2.o vec_dup_sse2.S
> > > > gcc -o test test.o memory.o broadcast.o vec_dup_sse2.o
> > > > ./test
> > > > memory  : 147215
> > > > broadcast   : 121213
> > > > vec_dup_sse2: 171366
> > > > $
> > > >
> > > > broadcast is also smaller:
> > > >
> > > > $ size memory.o broadcast.o
> > > >textdata bss dec hex filename
> > > > 132   0   0 132  84 memory.o
> > > > 122   0   0 122  7a broadcast.o
> > > > $
> > > >
> > > > 3. Update PR 87767 tests to expect integer broadcast instead of 
> > > > broadcast
> > > > from memory.
> > > > 4. Update avx512f_cond_move.c to expect integer broadcast.
> > > >
> > > > A small benchmark:
> > > >
> > > > https://gitlab.com/x86-benchmarks/microbenchmark/-/tree/vpaddd/broadcast
> > > >
> > > > shows that integer broadcast is faster than embedded memory

Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker

2021-06-26 Thread Artur Sinila via Gcc-patches
Not so gentle ping :)
What should happen in order for this patch to be accepted?


signature.asc
Description: This is a digitally signed message part


Re: PING^1 [PATCH v4 0/2] x86: Convert CONST_WIDE_INT/CONST_VECTOR to broadcast

2021-06-26 Thread H.J. Lu via Gcc-patches
On Sat, Jun 26, 2021 at 6:44 AM H.J. Lu  wrote:
>
> On Thu, Jun 24, 2021 at 11:04 PM Hongtao Liu  wrote:
> >
> > On Fri, Jun 25, 2021 at 2:01 PM Hongtao Liu  wrote:
> > >
> > > I didn't receive
> > > https://gcc.gnu.org/pipermail/gcc-patches/2021-June/572436.html in my
> > > gmail account, does anyone know why?
> > >
> > >
> > > >--- a/gcc/config/i386/i386-protos.h
> > > >+++ b/gcc/config/i386/i386-protos.h
> > > >@@ -260,6 +260,7 @@ extern void ix86_expand_mul_widen_hilo (rtx, rtx, 
> > > >rtx, bool, bool);
> > > > extern void ix86_expand_sse2_mulv4si3 (rtx, rtx, rtx);
> > > > extern void ix86_expand_sse2_mulvxdi3 (rtx, rtx, rtx);
> > > > extern void ix86_expand_sse2_abs (rtx, rtx);
> > > >+extern bool ix86_expand_integer_vec_duplicate (rtx *);
> > > >
> > > > /* In i386-c.c  */
> > > > extern void ix86_target_macros (void);
> > > >diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
> > > >index 2a34756be2a..f094e5a2586 100644
> > > >--- a/gcc/config/i386/sse.md
> > > >+++ b/gcc/config/i386/sse.md
> > > >@@ -24570,3 +24570,24 @@
> > > >   "TARGET_WIDEKL"
> > > >   "aes\t{%0}"
> > > >   [(set_attr "type" "other")])
> > > >+
> > > >+;; Modes handled by broadcast patterns.
> > > >+(define_mode_iterator INT_BROADCAST_MODE
> > > >+  [(V64QI "TARGET_AVX512F") (V32QI "TARGET_AVX") V16QI
> > > >+   (V32HI "TARGET_AVX512F") (V16HI "TARGET_AVX") V8HI
> > > >+   (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX") V4SI
> > > >+   (V8DI "TARGET_AVX512F && TARGET_64BIT")
> > > >+   (V4DI "TARGET_AVX && TARGET_64BIT") (V2DI "TARGET_64BIT")])
> > > TARGET_AVX512BW is needed for V64QI and V32HImode.
>
> I will fix them.

It turned out that ix86_expand_integer_vec_duplicate can expand
without TARGET_AVX512BW which is used by memset vector broadcast
expander to XI with:
 vmovd   %edi, %xmm15
 vpbroadcastb%xmm15, %ymm15
 vinserti64x4$0x1, %ymm15, %zmm15, %zmm15

I will keep INT_BROADCAST_MODE ASIS.

> > > And consider the scenario, TARGET_AVX2 is needed for all other
> > > 128/256-bit modes?
> >
> > Actually we can use vbroadcastss/d for SI/DImode which means
> > V2DI/V4DI/V8SI/4SI only need TARGET_AVX.
> >
> > (define_insn "vec_dup"
> >   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "=x,x,x,v,x")
> > (vec_duplicate:AVX_VEC_DUP_MODE
> >   (match_operand: 1 "nonimmediate_operand"
> > "m,m,x,v,?x")))]
> >   "TARGET_AVX"
> >
> > I saw in patch 1/2 TARGET_AVX2 is also needed for every modes.
>
> I will allow AVX with SI/DI broadcast.
>
> > > >+
> > > >+;; Broadcast from an integer.  NB: Enable broadcast only if we can move
> > > >+;; from GPR to SSE register directly.
> > > >+(define_expand "vec_duplicate"
> > > >+  [(set (match_operand:INT_BROADCAST_MODE 0 "register_operand")
> > > >+ (vec_duplicate:INT_BROADCAST_MODE
> > > >+   (match_operand: 1 "general_operand")))]
> > > >+  "TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC"
> > > Why not directly use TARGET_AVX2 here, not in 
> > > ix86_expand_integer_vec_duplicate.
>
> We allow SSE2 for variable broadcast.
>
> > > Also define some predicate to restrict operand[1] to be const_int but
> > > not const0_rtx and constm1_rtx.
> > > w/ this, guess there's no need for FAIL? and you can directly
> > > call ix86_expand_vector_init_duplicate.
>
> general_operand is used to allow both variable and constant broadcast
> so that I can use vector broadcast in memset with both variable and constant.
> Changing the predicate won't help SSE nor AVX for constant broadcast since
> the expander will generate a sequence of codes to satisfy the
> predicate.  If it is
> allowed to FAIL, the memset expander can use load from constant pool for
> SSE2 and AVX.
>
> > > >+{
> > > >+  if (!ix86_expand_integer_vec_duplicate (operands))
> > > >+FAIL;
> > > >+  DONE;
> > > >
> > >
> > > On Fri, Jun 25, 2021 at 1:30 AM H.J. Lu via Gcc-patches
> > >  wrote:
> > > >
> > > > On Wed, Jun 9, 2021 at 4:39 PM H.J. Lu  wrote:
> > > > >
> > > > > 1. Update move expanders to convert the CONST_WIDE_INT and CONST_VECTO
> > > > > operands to vector broadcast from an integer with AVX2.
> > > > > 2. Add ix86_gen_scratch_sse_rtx to return a scratch SSE register which
> > > > > won't increase stack alignment requirement and blocks transformation 
> > > > > by
> > > > > the combine pass.
> > > > >
> > > > > A small benchmark:
> > > > >
> > > > > https://gitlab.com/x86-benchmarks/microbenchmark/-/tree/memset/broadcast
> > > > >
> > > > > shows that broadcast is a little bit faster on Intel Core i7-8559U:
> > > > >
> > > > > $ make
> > > > > gcc -g -I. -O2   -c -o test.o test.c
> > > > > gcc -g   -c -o memory.o memory.S
> > > > > gcc -g   -c -o broadcast.o broadcast.S
> > > > > gcc -g   -c -o vec_dup_sse2.o vec_dup_sse2.S
> > > > > gcc -o test test.o memory.o broadcast.o vec_dup_sse2.o
> > > > > ./test
> > > > > memory  : 147215
> > > > > broadcast   : 121213
> > > > > vec_dup_sse2: 171366
> > > > > $
> > > > >
> > > > > broadcast is also smaller:
> > > > >
> > >

[PATCH v5 0/2] x86: Convert CONST_WIDE_INT/CONST_VECTOR to broadcast

2021-06-26 Thread H.J. Lu via Gcc-patches
Changes in the v5 patch:

1. Allow AVX with SI/DI broadcast.
2. Add a comment for broadcasting to V64QI and V32HI with AVX512F, but
without AVX512BW.

---
1. Update move expanders to convert the CONST_WIDE_INT and CONST_VECTO
operands to vector broadcast from an integer with AVX2.
2. Add ix86_gen_scratch_sse_rtx to return a scratch SSE register which
won't increase stack alignment requirement and blocks transformation by
the combine pass.

A small benchmark:

https://gitlab.com/x86-benchmarks/microbenchmark/-/tree/memset/broadcast

shows that broadcast is a little bit faster on Intel Core i7-8559U:

$ make
gcc -g -I. -O2   -c -o test.o test.c
gcc -g   -c -o memory.o memory.S
gcc -g   -c -o broadcast.o broadcast.S
gcc -g   -c -o vec_dup_sse2.o vec_dup_sse2.S
gcc -o test test.o memory.o broadcast.o vec_dup_sse2.o
./test
memory  : 147215
broadcast   : 121213
vec_dup_sse2: 171366
$

broadcast is also smaller:

$ size memory.o broadcast.o
   textdata bss dec hex filename
132   0   0 132  84 memory.o
122   0   0 122  7a broadcast.o
$

3. Update PR 87767 tests to expect integer broadcast instead of broadcast
from memory.
4. Update avx512f_cond_move.c to expect integer broadcast.

A small benchmark:

https://gitlab.com/x86-benchmarks/microbenchmark/-/tree/vpaddd/broadcast

shows that integer broadcast is faster than embedded memory broadcast:

$ make
gcc -g -I. -O2 -march=skylake-avx512   -c -o test.o test.c
gcc -g   -c -o memory.o memory.S
gcc -g   -c -o broadcast.o broadcast.S
gcc -o test test.o memory.o broadcast.o
./test
memory  : 425538
broadcast   : 375260
$

5. Update vec_duplicate to allow to fail so that backend can only allow
broadcasting an integer constant to a vector when broadcast instruction
is available.  This can be used by memset expander to avoid vec_duplicate
when loading from constant pool is more efficient.
6. Add vec_duplicate expander and enable vec_duplicate from a
non-standard SSE constant integer only if vector broadcast is available.

H.J. Lu (2):
  x86: Convert CONST_WIDE_INT/CONST_VECTOR to broadcast
  x86: Add vec_duplicate expander

 gcc/config/i386/i386-expand.c | 214 +-
 gcc/config/i386/i386-protos.h |   3 +
 gcc/config/i386/i386.c|  13 ++
 gcc/config/i386/sse.md|  28 +++
 gcc/doc/md.texi   |   2 -
 .../i386/avx512f-broadcast-pr87767-1.c|   7 +-
 .../i386/avx512f-broadcast-pr87767-5.c|   5 +-
 .../gcc.target/i386/avx512f_cond_move.c   |   4 +-
 .../i386/avx512vl-broadcast-pr87767-1.c   |  12 +-
 .../i386/avx512vl-broadcast-pr87767-5.c   |   9 +-
 gcc/testsuite/gcc.target/i386/pr100865-1.c|  13 ++
 gcc/testsuite/gcc.target/i386/pr100865-10a.c  |  33 +++
 gcc/testsuite/gcc.target/i386/pr100865-10b.c  |   7 +
 gcc/testsuite/gcc.target/i386/pr100865-11a.c  |  23 ++
 gcc/testsuite/gcc.target/i386/pr100865-11b.c  |   8 +
 gcc/testsuite/gcc.target/i386/pr100865-12a.c  |  20 ++
 gcc/testsuite/gcc.target/i386/pr100865-12b.c  |   8 +
 gcc/testsuite/gcc.target/i386/pr100865-2.c|  14 ++
 gcc/testsuite/gcc.target/i386/pr100865-3.c|  15 ++
 gcc/testsuite/gcc.target/i386/pr100865-4a.c   |  16 ++
 gcc/testsuite/gcc.target/i386/pr100865-4b.c   |   9 +
 gcc/testsuite/gcc.target/i386/pr100865-5a.c   |  16 ++
 gcc/testsuite/gcc.target/i386/pr100865-5b.c   |   9 +
 gcc/testsuite/gcc.target/i386/pr100865-6a.c   |  16 ++
 gcc/testsuite/gcc.target/i386/pr100865-6b.c   |   9 +
 gcc/testsuite/gcc.target/i386/pr100865-6c.c   |  16 ++
 gcc/testsuite/gcc.target/i386/pr100865-7a.c   |  17 ++
 gcc/testsuite/gcc.target/i386/pr100865-7b.c   |   9 +
 gcc/testsuite/gcc.target/i386/pr100865-7c.c   |  17 ++
 gcc/testsuite/gcc.target/i386/pr100865-8a.c   |  24 ++
 gcc/testsuite/gcc.target/i386/pr100865-8b.c   |   7 +
 gcc/testsuite/gcc.target/i386/pr100865-9a.c   |  25 ++
 gcc/testsuite/gcc.target/i386/pr100865-9b.c   |   7 +
 33 files changed, 609 insertions(+), 26 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-10a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-10b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-11a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-11b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-12a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-12b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-3.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-4a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-4b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-5a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-5b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100865-6a.c
 create mode 100644 gcc/testsuite/

[PATCH v5 2/2] x86: Add vec_duplicate expander

2021-06-26 Thread H.J. Lu via Gcc-patches
1. Update vec_duplicate to allow to fail so that backend can only allow
broadcasting an integer constant to a vector when broadcast instruction
is available.  This can be used by memset expander to avoid vec_duplicate
when loading from constant pool is more efficient.
2. Add vec_duplicate expander and enable vec_duplicate from a
non-standard SSE constant integer only if vector broadcast is available.

* config/i386/i386-expand.c (ix86_expand_integer_vec_duplicate):
New function.
* config/i386/i386-protos.h (ix86_expand_integer_vec_duplicat):
New prototype.
* config/i386/sse.md (INT_BROADCAST_MODE): New mode iterator.
(vec_duplicate): New expander.
* doc/md.texi: Update vec_duplicate.
---
 gcc/config/i386/i386-expand.c | 24 
 gcc/config/i386/i386-protos.h |  1 +
 gcc/config/i386/sse.md| 28 
 gcc/doc/md.texi   |  2 --
 4 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index e9e89c82764..75c160d4349 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -15742,6 +15742,30 @@ ix86_expand_vector_extract (bool mmx_ok, rtx target, 
rtx vec, int elt)
 }
 }
 
+/* Expand integer vec_duplicate.  Return true if successful.  */
+
+bool
+ix86_expand_integer_vec_duplicate (rtx *operands)
+{
+  /* Enable VEC_DUPLICATE from a non-standard SSE constant integer only
+ if vector broadcast is available.  */
+  machine_mode mode = GET_MODE (operands[0]);
+  if (CONST_INT_P (operands[1])
+  && (!(TARGET_AVX2
+   || (TARGET_AVX
+   && (GET_MODE_INNER (mode) == SImode
+   || GET_MODE_INNER (mode) == DImode)))
+ || standard_sse_constant_p (operands[1], mode)))
+return false;
+
+  bool ok = ix86_expand_vector_init_duplicate (false, mode,
+  operands[0],
+  operands[1]);
+  gcc_assert (ok);
+
+  return true;
+}
+
 /* Generate code to copy vector bits i / 2 ... i - 1 from vector SRC
to bits 0 ... i / 2 - 1 of vector DEST, which has the same mode.
The upper bits of DEST are undefined, though they shouldn't cause
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index 71745b9a1ea..a6cc09bb75b 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -258,6 +258,7 @@ extern void ix86_expand_mul_widen_hilo (rtx, rtx, rtx, 
bool, bool);
 extern void ix86_expand_sse2_mulv4si3 (rtx, rtx, rtx);
 extern void ix86_expand_sse2_mulvxdi3 (rtx, rtx, rtx);
 extern void ix86_expand_sse2_abs (rtx, rtx);
+extern bool ix86_expand_integer_vec_duplicate (rtx *);
 
 /* In i386-c.c  */
 extern void ix86_target_macros (void);
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index e4f01e64bc1..53a703fb466 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -24640,3 +24640,31 @@ (define_insn "*aesu8"
   "TARGET_WIDEKL"
   "aes\t{%0}"
   [(set_attr "type" "other")])
+
+;; Modes handled by broadcast patterns.  NB: Allow V64QI and V32HI with
+;; TARGET_AVX512F since ix86_expand_integer_vec_duplicate can expand
+;; without TARGET_AVX512BW which is used by memset vector broadcast
+;; expander to XI with:
+;; vmovd   %edi, %xmm15
+;; vpbroadcastb%xmm15, %ymm15
+;; vinserti64x4$0x1, %ymm15, %zmm15, %zmm15
+
+(define_mode_iterator INT_BROADCAST_MODE
+  [(V64QI "TARGET_AVX512F") (V32QI "TARGET_AVX") V16QI
+   (V32HI "TARGET_AVX512F") (V16HI "TARGET_AVX") V8HI
+   (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX") V4SI
+   (V8DI "TARGET_AVX512F && TARGET_64BIT")
+   (V4DI "TARGET_AVX && TARGET_64BIT") (V2DI "TARGET_64BIT")])
+
+;; Broadcast from an integer.  NB: Enable broadcast only if we can move
+;; from GPR to SSE register directly.
+(define_expand "vec_duplicate"
+  [(set (match_operand:INT_BROADCAST_MODE 0 "register_operand")
+   (vec_duplicate:INT_BROADCAST_MODE
+ (match_operand: 1 "general_operand")))]
+  "TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC"
+{
+  if (!ix86_expand_integer_vec_duplicate (operands))
+FAIL;
+  DONE;
+})
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 1b918144330..a892c94d163 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -5077,8 +5077,6 @@ the mode appropriate for one element of @var{m}.
 This pattern only handles duplicates of non-constant inputs.  Constant
 vectors go through the @code{mov@var{m}} pattern instead.
 
-This pattern is not allowed to @code{FAIL}.
-
 @cindex @code{vec_series@var{m}} instruction pattern
 @item @samp{vec_series@var{m}}
 Initialize vector output operand 0 so that element @var{i} is equal to
-- 
2.31.1



[PATCH v5 1/2] x86: Convert CONST_WIDE_INT/CONST_VECTOR to broadcast

2021-06-26 Thread H.J. Lu via Gcc-patches
1. Update move expanders to convert the CONST_WIDE_INT and CONST_VECTO
operands to vector broadcast from an integer with AVX2.
2. Add ix86_gen_scratch_sse_rtx to return a scratch SSE register which
won't increase stack alignment requirement and blocks transformation by
the combine pass.

A small benchmark:

https://gitlab.com/x86-benchmarks/microbenchmark/-/tree/memset/broadcast

shows that broadcast is a little bit faster on Intel Core i7-8559U:

$ make
gcc -g -I. -O2   -c -o test.o test.c
gcc -g   -c -o memory.o memory.S
gcc -g   -c -o broadcast.o broadcast.S
gcc -g   -c -o vec_dup_sse2.o vec_dup_sse2.S
gcc -o test test.o memory.o broadcast.o vec_dup_sse2.o
./test
memory  : 147215
broadcast   : 121213
vec_dup_sse2: 171366
$

broadcast is also smaller:

$ size memory.o broadcast.o
   textdata bss dec hex filename
132   0   0 132  84 memory.o
122   0   0 122  7a broadcast.o
$

3. Update PR 87767 tests to expect integer broadcast instead of broadcast
from memory.
4. Update avx512f_cond_move.c to expect integer broadcast.

A small benchmark:

https://gitlab.com/x86-benchmarks/microbenchmark/-/tree/vpaddd/broadcast

shows that integer broadcast is faster than embedded memory broadcast:

$ make
gcc -g -I. -O2 -march=skylake-avx512   -c -o test.o test.c
gcc -g   -c -o memory.o memory.S
gcc -g   -c -o broadcast.o broadcast.S
gcc -o test test.o memory.o broadcast.o
./test
memory  : 425538
broadcast   : 375260
$

gcc/

PR target/100865
* config/i386/i386-expand.c (ix86_expand_vector_init_duplicate):
New prototype.
(ix86_byte_broadcast): New function.
(ix86_convert_const_wide_int_to_broadcast): Likewise.
(ix86_expand_move): Convert CONST_WIDE_INT to broadcast if mode
size is 16 bytes or bigger.
(ix86_broadcast_from_integer_constant): New function.
(ix86_expand_vector_move): Convert CONST_WIDE_INT and CONST_VECTOR
to broadcast if mode size is 16 bytes or bigger.
* config/i386/i386-protos.h (ix86_gen_scratch_sse_rtx): New
prototype.
* config/i386/i386.c (ix86_gen_scratch_sse_rtx): New function.

gcc/testsuite/

PR target/100865
* gcc.target/i386/avx512f-broadcast-pr87767-1.c: Expect integer
broadcast.
* gcc.target/i386/avx512f-broadcast-pr87767-5.c: Likewise.
* gcc.target/i386/avx512vl-broadcast-pr87767-1.c: Likewise.
* gcc.target/i386/avx512vl-broadcast-pr87767-5.c: Likewise.
* gcc.target/i386/avx512f_cond_move.c: Also pass
-mprefer-vector-width=512 and expect integer broadcast.
* gcc.target/i386/pr100865-1.c: New test.
* gcc.target/i386/pr100865-2.c: Likewise.
* gcc.target/i386/pr100865-3.c: Likewise.
* gcc.target/i386/pr100865-4a.c: Likewise.
* gcc.target/i386/pr100865-4b.c: Likewise.
* gcc.target/i386/pr100865-5a.c: Likewise.
* gcc.target/i386/pr100865-5b.c: Likewise.
* gcc.target/i386/pr100865-6a.c: Likewise.
* gcc.target/i386/pr100865-6b.c: Likewise.
* gcc.target/i386/pr100865-6c.c: Likewise.
* gcc.target/i386/pr100865-7a.c: Likewise.
* gcc.target/i386/pr100865-7b.c: Likewise.
* gcc.target/i386/pr100865-7c.c: Likewise.
* gcc.target/i386/pr100865-8a.c: Likewise.
* gcc.target/i386/pr100865-8b.c: Likewise.
* gcc.target/i386/pr100865-9a.c: Likewise.
* gcc.target/i386/pr100865-9b.c: Likewise.
* gcc.target/i386/pr100865-10a.c: Likewise.
* gcc.target/i386/pr100865-10b.c: Likewise.
* gcc.target/i386/pr100865-11a.c: Likewise.
* gcc.target/i386/pr100865-11b.c: Likewise.
* gcc.target/i386/pr100865-12a.c: Likewise.
* gcc.target/i386/pr100865-12b.c: Likewise.
---
 gcc/config/i386/i386-expand.c | 190 --
 gcc/config/i386/i386-protos.h |   2 +
 gcc/config/i386/i386.c|  13 ++
 .../i386/avx512f-broadcast-pr87767-1.c|   7 +-
 .../i386/avx512f-broadcast-pr87767-5.c|   5 +-
 .../gcc.target/i386/avx512f_cond_move.c   |   4 +-
 .../i386/avx512vl-broadcast-pr87767-1.c   |  12 +-
 .../i386/avx512vl-broadcast-pr87767-5.c   |   9 +-
 gcc/testsuite/gcc.target/i386/pr100865-1.c|  13 ++
 gcc/testsuite/gcc.target/i386/pr100865-10a.c  |  33 +++
 gcc/testsuite/gcc.target/i386/pr100865-10b.c  |   7 +
 gcc/testsuite/gcc.target/i386/pr100865-11a.c  |  23 +++
 gcc/testsuite/gcc.target/i386/pr100865-11b.c  |   8 +
 gcc/testsuite/gcc.target/i386/pr100865-12a.c  |  20 ++
 gcc/testsuite/gcc.target/i386/pr100865-12b.c  |   8 +
 gcc/testsuite/gcc.target/i386/pr100865-2.c|  14 ++
 gcc/testsuite/gcc.target/i386/pr100865-3.c|  15 ++
 gcc/testsuite/gcc.target/i386/pr100865-4a.c   |  16 ++
 gcc/testsuite/gcc.target/i386/pr100865-4b.c   |   9 +
 gcc/testsuite/gcc.target/i386/pr100865-5a.c   |  16 ++
 gcc/testsuite/gcc.target/i386/pr100865-5b