From: "H.J. Lu" <hjl.tools@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Richard Sandiford <richard.sandiford@arm.com>,
Uros Bizjak <ubizjak@gmail.com>,
Bernd Edlinger <bernd.edlinger@hotmail.de>
Subject: Re: [PATCH v4 12/12] constructor: Check if it is faster to load constant from memory
Date: Wed, 19 May 2021 06:22:06 -0700 [thread overview]
Message-ID: <CAMe9rOp6c6LRfFk4=GagbY4YbidOpfUoxU2WYzgEEMS03zHndQ@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc3MYLY5r+Mmpe8+w=dUwXaS0Ar-4kyTSjxHhhCYWST4iw@mail.gmail.com>
On Wed, May 19, 2021 at 2:33 AM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Tue, May 18, 2021 at 9:16 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > When expanding a constant constructor, don't call expand_constructor if
> > it is more efficient to load the data from the memory via move by pieces.
> >
> > gcc/
> >
> > PR middle-end/90773
> > * expr.c (expand_expr_real_1): Don't call expand_constructor if
> > it is more efficient to load the data from the memory.
> >
> > gcc/testsuite/
> >
> > PR middle-end/90773
> > * gcc.target/i386/pr90773-24.c: New test.
> > * gcc.target/i386/pr90773-25.c: Likewise.
> > ---
> > gcc/expr.c | 10 ++++++++++
> > gcc/testsuite/gcc.target/i386/pr90773-24.c | 22 ++++++++++++++++++++++
> > gcc/testsuite/gcc.target/i386/pr90773-25.c | 20 ++++++++++++++++++++
> > 3 files changed, 52 insertions(+)
> > create mode 100644 gcc/testsuite/gcc.target/i386/pr90773-24.c
> > create mode 100644 gcc/testsuite/gcc.target/i386/pr90773-25.c
> >
> > diff --git a/gcc/expr.c b/gcc/expr.c
> > index d09ee42e262..80e01ea1cbe 100644
> > --- a/gcc/expr.c
> > +++ b/gcc/expr.c
> > @@ -10886,6 +10886,16 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
> > unsigned HOST_WIDE_INT ix;
> > tree field, value;
> >
> > + /* Check if it is more efficient to load the data from
> > + the memory directly. FIXME: How many stores do we
> > + need here if not moved by pieces? */
> > + unsigned HOST_WIDE_INT bytes
> > + = tree_to_uhwi (TYPE_SIZE_UNIT (type));
>
> that's prone to fail - it could be a VLA.
What do you mean by fail? Is it ICE or missed optimization?
Do you have a testcase?
>
> > + if ((bytes / UNITS_PER_WORD) > 2
> > + && MOVE_MAX_PIECES > UNITS_PER_WORD
> > + && can_move_by_pieces (bytes, TYPE_ALIGN (type)))
> > + goto normal_inner_ref;
> > +
>
> It looks like you're concerned about aggregate copies but this also handles
> non-aggregates (which on GIMPLE might already be optimized of course).
Here I check if we copy more than 2 words and we can move more than
a word in a single instruction.
> Also you say "if it's cheaper" but I see no cost considerations. How do
> we generally handle immed const vs. load from constant pool costs?
This trades 2 (update to 8) stores with one load plus one store. Is there
a way to check which one is faster?
> > FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
> > field, value)
> > if (tree_int_cst_equal (field, index))
> > diff --git a/gcc/testsuite/gcc.target/i386/pr90773-24.c b/gcc/testsuite/gcc.target/i386/pr90773-24.c
> > new file mode 100644
> > index 00000000000..4a4b62533dc
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr90773-24.c
> > @@ -0,0 +1,22 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -march=x86-64" } */
> > +
> > +struct S
> > +{
> > + long long s1 __attribute__ ((aligned (8)));
> > + unsigned s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
> > +};
> > +
> > +const struct S array[] = {
> > + { 0, 60, 640, 2112543726, 39682, 48, 16, 33, 10, 96, 2, 0, 0, 4 }
> > +};
> > +
> > +void
> > +foo (struct S *x)
> > +{
> > + x[0] = array[0];
> > +}
> > +/* { dg-final { scan-assembler-times "movups\[\\t \]%xmm\[0-9\]+, \\(%\[\^,\]+\\)" 1 } } */
> > +/* { dg-final { scan-assembler-times "movups\[\\t \]%xmm\[0-9\]+, 16\\(%\[\^,\]+\\)" 1 } } */
> > +/* { dg-final { scan-assembler-times "movups\[\\t \]%xmm\[0-9\]+, 32\\(%\[\^,\]+\\)" 1 } } */
> > +/* { dg-final { scan-assembler-times "movups\[\\t \]%xmm\[0-9\]+, 48\\(%\[\^,\]+\\)" 1 } } */
> > diff --git a/gcc/testsuite/gcc.target/i386/pr90773-25.c b/gcc/testsuite/gcc.target/i386/pr90773-25.c
> > new file mode 100644
> > index 00000000000..2520b670989
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr90773-25.c
> > @@ -0,0 +1,20 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -march=skylake" } */
> > +
> > +struct S
> > +{
> > + long long s1 __attribute__ ((aligned (8)));
> > + unsigned s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
> > +};
> > +
> > +const struct S array[] = {
> > + { 0, 60, 640, 2112543726, 39682, 48, 16, 33, 10, 96, 2, 0, 0, 4 }
> > +};
> > +
> > +void
> > +foo (struct S *x)
> > +{
> > + x[0] = array[0];
> > +}
> > +/* { dg-final { scan-assembler-times "vmovdqu\[\\t \]%ymm\[0-9\]+, \\(%\[\^,\]+\\)" 1 } } */
> > +/* { dg-final { scan-assembler-times "vmovdqu\[\\t \]%ymm\[0-9\]+, 32\\(%\[\^,\]+\\)" 1 } } */
> > --
> > 2.31.1
> >
--
H.J.
next prev parent reply other threads:[~2021-05-19 13:22 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-18 19:16 [PATCH v4 00/12] Allow TImode/OImode/XImode in op_by_pieces operations H.J. Lu
2021-05-18 19:16 ` [PATCH v4 01/12] Add TARGET_READ_MEMSET_VALUE/TARGET_GEN_MEMSET_VALUE H.J. Lu
2021-05-19 9:25 ` Richard Biener
2021-05-19 12:55 ` H.J. Lu
2021-05-20 20:49 ` [PATCH] Add 3 target hooks for memset H.J. Lu
2021-05-21 5:42 ` Bernd Edlinger
2021-05-21 11:53 ` H.J. Lu
2021-05-25 14:34 ` Richard Biener
2021-05-25 15:11 ` H.J. Lu
2021-05-26 8:28 ` Richard Biener
2021-05-31 12:09 ` [PATCH] Add integer_extract and vec_const_duplicate optabs H.J. Lu
2021-05-31 12:46 ` Richard Biener
2021-05-31 13:12 ` H.J. Lu
2021-05-31 13:25 ` Richard Biener
2021-05-31 13:32 ` H.J. Lu
2021-05-31 13:36 ` H.J. Lu
2021-05-31 20:22 ` [PATCH v2] Add vec_const_duplicate optab and TARGET_GEN_MEMSET_SCRATCH_RTX H.J. Lu
2021-06-01 5:50 ` Richard Sandiford
2021-06-01 5:54 ` Jeff Law
2021-06-01 13:05 ` H.J. Lu
2021-06-01 13:25 ` Richard Biener
2021-06-01 13:29 ` H.J. Lu
2021-06-01 14:21 ` Jeff Law
2021-06-01 23:07 ` H.J. Lu
2021-06-02 1:21 ` Hongtao Liu
2021-06-02 1:54 ` H.J. Lu
2021-06-02 7:02 ` Richard Biener
2021-06-02 13:50 ` H.J. Lu
2021-05-18 19:16 ` [PATCH v4 02/12] x86: Add TARGET_READ_MEMSET_VALUE/TARGET_GEN_MEMSET_VALUE H.J. Lu
2021-05-18 19:16 ` [PATCH v4 03/12] x86: Avoid stack realignment when copying data H.J. Lu
2021-05-18 19:16 ` [PATCH v4 04/12] Remove MAX_BITSIZE_MODE_ANY_INT H.J. Lu
2021-05-25 14:37 ` Richard Biener
2021-05-18 19:16 ` [PATCH v4 05/12] x86: Update piecewise move and store H.J. Lu
2021-05-18 19:16 ` [PATCH v4 06/12] x86: Add AVX2 tests for PR middle-end/90773 H.J. Lu
2021-05-18 19:16 ` [PATCH v4 07/12] x86: Add tests for piecewise move and store H.J. Lu
2021-05-18 19:16 ` [PATCH v4 08/12] x86: Also pass -mno-avx to pr72839.c H.J. Lu
2021-05-18 19:16 ` [PATCH v4 09/12] x86: Also pass -mno-avx to cold-attribute-1.c H.J. Lu
2021-05-18 19:16 ` [PATCH v4 10/12] x86: Also pass -mno-avx to sw-1.c for ia32 H.J. Lu
2021-05-18 19:16 ` [PATCH v4 11/12] x86: Update gcc.target/i386/incoming-11.c H.J. Lu
2021-05-18 19:16 ` [PATCH v4 12/12] constructor: Check if it is faster to load constant from memory H.J. Lu
2021-05-19 9:33 ` Richard Biener
2021-05-19 13:22 ` H.J. Lu [this message]
2021-05-19 13:27 ` Bernd Edlinger
2021-05-19 19:04 ` H.J. Lu
2021-05-20 6:57 ` Richard Biener
2021-05-20 7:51 ` Richard Biener
2021-05-20 14:03 ` [PATCH] constructor: Elide expand_constructor when can move by pieces is true H.J. Lu
2021-05-21 5:35 ` Bernd Edlinger
2021-05-21 6:57 ` Richard Biener
2021-05-21 7:30 ` Bernd Edlinger
2021-05-21 13:13 ` H.J. Lu
2021-05-21 13:09 ` [PATCH] Elide expand_constructor if move by pieces is preferred 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='CAMe9rOp6c6LRfFk4=GagbY4YbidOpfUoxU2WYzgEEMS03zHndQ@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=bernd.edlinger@hotmail.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.guenther@gmail.com \
--cc=richard.sandiford@arm.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).