From: Uros Bizjak <ubizjak@gmail.com>
To: liuhongt <hongtao.liu@intel.com>
Cc: gcc-patches@gcc.gnu.org, crazylht@gmail.com, hjl.tools@gmail.com
Subject: Re: [PATCH 2/2] [x86] Adjust rtx_cost for MEM to enable more simplication
Date: Tue, 21 May 2024 08:50:12 +0200 [thread overview]
Message-ID: <CAFULd4YQF+HbxpRoSR3qNKYbdo57_T8gQuP3SytC5_UYiwGx1Q@mail.gmail.com> (raw)
In-Reply-To: <20240521051220.8653-2-hongtao.liu@intel.com>
On Tue, May 21, 2024 at 7:13 AM liuhongt <hongtao.liu@intel.com> wrote:
>
> For CONST_VECTOR_DUPLICATE_P in constant_pool, it is just broadcast or
> variants in ix86_vector_duplicate_simode_const.
> Adjust the cost to COSTS_N_INSNS (2) + speed which should be a little
> bit larger than broadcast.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk?
>
> gcc/ChangeLog:
> PR target/114428
> * config/i386/i386.cc (ix86_rtx_costs): Adjust cost for
> CONST_VECTOR_DUPLICATE_P in constant_pool.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr114428.c: New test.
LGTM.
Thanks,
Uros.
> ---
> gcc/config/i386/i386-expand.cc | 2 +-
> gcc/config/i386/i386-protos.h | 1 +
> gcc/config/i386/i386.cc | 13 +++++++++++++
> gcc/testsuite/gcc.target/i386/pr114428.c | 18 ++++++++++++++++++
> 4 files changed, 33 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr114428.c
>
> diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> index 4e16aedc5c1..d96c365e144 100644
> --- a/gcc/config/i386/i386-expand.cc
> +++ b/gcc/config/i386/i386-expand.cc
> @@ -588,7 +588,7 @@ ix86_expand_move (machine_mode mode, rtx operands[])
>
> /* OP is a memref of CONST_VECTOR, return scalar constant mem
> if CONST_VECTOR is a vec_duplicate, else return NULL. */
> -static rtx
> +rtx
> ix86_broadcast_from_constant (machine_mode mode, rtx op)
> {
> int nunits = GET_MODE_NUNITS (mode);
> diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
> index dbc861fb1ea..90712769200 100644
> --- a/gcc/config/i386/i386-protos.h
> +++ b/gcc/config/i386/i386-protos.h
> @@ -107,6 +107,7 @@ extern void ix86_expand_clear (rtx);
> extern void ix86_expand_move (machine_mode, rtx[]);
> extern void ix86_expand_vector_move (machine_mode, rtx[]);
> extern void ix86_expand_vector_move_misalign (machine_mode, rtx[]);
> +extern rtx ix86_broadcast_from_constant (machine_mode, rtx);
> extern rtx ix86_fixup_binary_operands (enum rtx_code, machine_mode,
> rtx[], bool = false);
> extern void ix86_fixup_binary_operands_no_copy (enum rtx_code, machine_mode,
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index b4838b7939e..fdd9343e47a 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -22197,6 +22197,19 @@ ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno,
> return true;
>
> case MEM:
> + /* CONST_VECTOR_DUPLICATE_P in constant_pool is just broadcast.
> + or variants in ix86_vector_duplicate_simode_const. */
> +
> + if (GET_MODE_SIZE (mode) >= 16
> + && VECTOR_MODE_P (mode)
> + && SYMBOL_REF_P (XEXP (x, 0))
> + && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))
> + && ix86_broadcast_from_constant (mode, x))
> + {
> + *total = COSTS_N_INSNS (2) + speed;
> + return true;
> + }
> +
> /* An insn that accesses memory is slightly more expensive
> than one that does not. */
> if (speed)
> diff --git a/gcc/testsuite/gcc.target/i386/pr114428.c b/gcc/testsuite/gcc.target/i386/pr114428.c
> new file mode 100644
> index 00000000000..bbbc5a080f6
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr114428.c
> @@ -0,0 +1,18 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=x86-64-v3 -mno-avx512f -O2" } */
> +/* { dg-final { scan-assembler-not "vpsra[dw]" } } */
> +
> +void
> +foo2 (char* __restrict a, short* b)
> +{
> + for (int i = 0; i != 32; i++)
> + a[i] = b[i] >> (short)8;
> +}
> +
> +void
> +foo3 (char* __restrict a, short* b)
> +{
> + for (int i = 0; i != 16; i++)
> + a[i] = b[i] >> (short)8;
> +}
> +
> --
> 2.31.1
>
next prev parent reply other threads:[~2024-05-21 6:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 5:12 [PATCH 1/2] Simplify (AND (ASHIFTRT A imm) mask) to (LSHIFTRT A imm) for vector mode liuhongt
2024-05-21 5:12 ` [PATCH 2/2] [x86] Adjust rtx_cost for MEM to enable more simplication liuhongt
2024-05-21 6:50 ` Uros Bizjak [this message]
2024-05-24 2:25 ` [PATCH 1/2] Simplify (AND (ASHIFTRT A imm) mask) to (LSHIFTRT A imm) for vector mode Hongtao Liu
2024-06-04 13:50 ` Jeff Law
2024-06-05 4:22 ` [V2 PATCH] " liuhongt
2024-06-05 14:43 ` Jeff Law
2024-06-06 0:32 ` Hongtao Liu
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=CAFULd4YQF+HbxpRoSR3qNKYbdo57_T8gQuP3SytC5_UYiwGx1Q@mail.gmail.com \
--to=ubizjak@gmail.com \
--cc=crazylht@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hjl.tools@gmail.com \
--cc=hongtao.liu@intel.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).