From: Uros Bizjak <ubizjak@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
Jakub Jelinek <jakub@redhat.com>,
Richard Sandiford <richard.sandiford@arm.com>,
Richard Biener <richard.guenther@gmail.com>
Subject: Re: [PATCH v3 2/2] x86: Add vec_duplicate<mode> expander
Date: Wed, 9 Jun 2021 08:40:51 +0200 [thread overview]
Message-ID: <CAFULd4ZXrWeQxYj4gj1q2LOwdwkjvXJ+jz_uxQYE=u-t5a5u6g@mail.gmail.com> (raw)
In-Reply-To: <20210608175918.61759-3-hjl.tools@gmail.com>
On Tue, Jun 8, 2021 at 7:59 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> 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<mode> 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<mode>): New expander.
> * doc/md.texi: Update vec_duplicate.
> ---
> gcc/config/i386/i386-expand.c | 21 +++++++++++++++++++++
> gcc/config/i386/i386-protos.h | 1 +
> gcc/config/i386/sse.md | 20 ++++++++++++++++++++
> gcc/doc/md.texi | 2 --
> 4 files changed, 42 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
> index 29d96805d9d..145e028353c 100644
> --- a/gcc/config/i386/i386-expand.c
> +++ b/gcc/config/i386/i386-expand.c
> @@ -15669,6 +15669,27 @@ 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. */
> + if (CONST_INT_P (operands[1])
> + && (!TARGET_AVX2
> + || standard_sse_constant_p (operands[1],
> + GET_MODE (operands[0]))))
> + return false;
> +
> + if (!ix86_expand_vector_init_duplicate (false,
> + GET_MODE (operands[0]),
> + operands[0], operands[1]))
> + gcc_unreachable ();
> +
> + 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 578750a2532..dc191dc18ec 100644
> --- 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..a227295cc1d 100644
> --- a/gcc/config/i386/sse.md
> +++ b/gcc/config/i386/sse.md
> @@ -24570,3 +24570,23 @@
> "TARGET_WIDEKL"
> "aes<aeswideklvariant>\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") (V4DI "TARGET_64BIT") V2DI])
In ix86_convert_const_wide_int_to_broadcast, there is:
+ else if (TARGET_64BIT
+ && ix86_broadcast (val, GET_MODE_BITSIZE (DImode),
+ val_broadcast))
So, shouldn't all modes with DImode inner mode have TARGET_64BIT predicate?
Uros.
> +;; Broadcast from an integer. NB: Enable broadcast only if we can move
> +;; from GPR to SSE register directly.
> +(define_expand "vec_duplicate<mode>"
> + [(set (match_operand:INT_BROADCAST_MODE 0 "register_operand")
> + (vec_duplicate:INT_BROADCAST_MODE
> + (match_operand:<ssescalarmode> 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 00caf3844cc..e66c41c4779 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
>
next prev parent reply other threads:[~2021-06-09 6:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-08 17:59 [PATCH v3 0/2] x86: Convert CONST_WIDE_INT/CONST_VECTOR to broadcast H.J. Lu
2021-06-08 17:59 ` [PATCH v3 1/2] " H.J. Lu
2021-06-09 8:17 ` Hongtao Liu
2021-06-09 12:56 ` H.J. Lu
2021-06-08 17:59 ` [PATCH v3 2/2] x86: Add vec_duplicate<mode> expander H.J. Lu
2021-06-09 6:40 ` Uros Bizjak [this message]
2021-06-09 23:30 ` H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFULd4ZXrWeQxYj4gj1q2LOwdwkjvXJ+jz_uxQYE=u-t5a5u6g@mail.gmail.com' \
--to=ubizjak@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hjl.tools@gmail.com \
--cc=jakub@redhat.com \
--cc=richard.guenther@gmail.com \
--cc=richard.sandiford@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).