From: Richard Biener <richard.guenther@gmail.com>
To: Alexandre Oliva <oliva@adacore.com>
Cc: gcc-patches@gcc.gnu.org, "H.J. Lu" <hjl.tools@gmail.com>,
Jan Hubicka <hubicka@ucw.cz>, Uros Bizjak <ubizjak@gmail.com>
Subject: Re: [PATCH] [x86] reenable dword MOVE_MAX for better memmove inlining
Date: Wed, 24 May 2023 11:12:22 +0200 [thread overview]
Message-ID: <CAFiYyc069Qz=RYjt5NhARwRYiRjLw4tP5pDcEvoM3xsLtcvrRg@mail.gmail.com> (raw)
In-Reply-To: <oredn6p9gk.fsf@lxoliva.fsfla.org>
On Wed, May 24, 2023 at 7:47 AM Alexandre Oliva via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
>
> MOVE_MAX on x86* used to accept up to 16 bytes, even without SSE,
> which enabled inlining of small memmove by loading and then storing
> the entire range. After the "x86: Update piecewise move and store"
> r12-2666 change, memmove of more than 4 bytes would not be inlined in
> gimple_fold_bultin_memory_op, failing the expectations of a few tests.
>
> I can see how lowering it for MOVE_MAX_PIECES can get us better
> codegen decisions overall, but surely inlining memmove with 2 32-bit
> loads and stores is better than an outline call that requires setting
> up 3 arguments. I suppose even 3 or 4 could do better. But maybe it
> is gimple_fold_builtin_memory_op that needs tweaking?
gimple_fold_builtin_memory_op tries to expand the call to a single
load plus a single store so we can handle overlaps by first loading
everything to registers and then storing:
/* If we can perform the copy efficiently with first doing all loads
and then all stores inline it that way. Currently efficiently
means that we can load all the memory into a single integer
register which is what MOVE_MAX gives us. */
using DImode on i?86 without SSE means we eventually perform two
loads and two stores which means we need two registers available.
That might not be an issue on x86_64 doing 16 bytes with two DImode
ops (and -mno-sse) since there's plenty of regs available.
So I think if we want to expand this further at the GIMPLE level we
should still honor MOVE_MAX but eventually emit multiple loads/stores
honoring the MOVE_MAX_PIECES set of constraints there and avoid
expanding to sequences where we cannot interleave the loads/stores
(aka for the memmove case).
> Anyhow, this patch raises MOVE_MAX back a little for non-SSE targets,
> while preserving the new value for MOVE_MAX_PIECES.
>
> Bootstrapped on x86_64-linux-gnu. Also tested on ppc- and x86-vx7r2
> with gcc-12.
>
> for gcc/ChangeLog
>
> * config/i386/i386.h (MOVE_MAX): Rename to...
> (MOVE_MAX_VEC): ... this. Add NONVEC parameter, and use it as
> the last resort, instead of UNITS_PER_WORD.
> (MOVE_MAX): Reintroduce in terms of MOVE_MAX_VEC, with
> 2*UNITS_PER_WORD.
> (MOVE_MAX_PIECES): Likewise, but with UNITS_PER_WORD.
> ---
> gcc/config/i386/i386.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> index c7439f89bdf92..5293a332a969a 100644
> --- a/gcc/config/i386/i386.h
> +++ b/gcc/config/i386/i386.h
> @@ -1801,7 +1801,9 @@ typedef struct ix86_args {
> is the number of bytes at a time which we can move efficiently.
> MOVE_MAX_PIECES defaults to MOVE_MAX. */
>
> -#define MOVE_MAX \
> +#define MOVE_MAX MOVE_MAX_VEC (2 * UNITS_PER_WORD)
> +#define MOVE_MAX_PIECES MOVE_MAX_VEC (UNITS_PER_WORD)
> +#define MOVE_MAX_VEC(NONVEC) \
> ((TARGET_AVX512F \
> && (ix86_move_max == PVW_AVX512 \
> || ix86_store_max == PVW_AVX512)) \
> @@ -1813,7 +1815,7 @@ typedef struct ix86_args {
> : ((TARGET_SSE2 \
> && TARGET_SSE_UNALIGNED_LOAD_OPTIMAL \
> && TARGET_SSE_UNALIGNED_STORE_OPTIMAL) \
> - ? 16 : UNITS_PER_WORD)))
> + ? 16 : (NONVEC))))
>
> /* STORE_MAX_PIECES is the number of bytes at a time that we can store
> efficiently. Allow 16/32/64 bytes only if inter-unit move is enabled
>
> --
> Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
> Free Software Activist GNU Toolchain Engineer
> Disinformation flourishes because many people care deeply about injustice
> but very few check the facts. Ask me about <https://stallmansupport.org>
next prev parent reply other threads:[~2023-05-24 9:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-24 5:47 Alexandre Oliva
2023-05-24 9:12 ` Richard Biener [this message]
2023-05-25 10:01 ` Alexandre Oliva
2023-05-25 10:49 ` Richard Biener
2023-05-25 11:10 ` Alexandre Oliva
2023-05-25 11:33 ` Richard Biener
2023-05-25 13:25 ` Alexandre Oliva
2023-05-25 13:32 ` Richard Biener
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='CAFiYyc069Qz=RYjt5NhARwRYiRjLw4tP5pDcEvoM3xsLtcvrRg@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hjl.tools@gmail.com \
--cc=hubicka@ucw.cz \
--cc=oliva@adacore.com \
--cc=ubizjak@gmail.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).