public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/94092] Code size and performance degradations after -ftree-loop-distribute-patterns was enabled at -O[2s]+
Date: Wed, 03 Mar 2021 08:03:57 +0000 [thread overview]
Message-ID: <bug-94092-4-TCkcBCXimi@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94092-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94092
--- Comment #12 from rguenther at suse dot de <rguenther at suse dot de> ---
On Wed, 3 Mar 2021, bina2374 at gmail dot com wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94092
>
> --- Comment #11 from Mel Chen <bina2374 at gmail dot com> ---
> (In reply to Mel Chen from comment #10)
> > (In reply to Richard Biener from comment #9)
> > > (In reply to Mel Chen from comment #8)
> > > > Sorry for using the bad example to describe the problem I am facing. Let me
> > > > clarify my question with a more precise example.
> > > >
> > > > void array_mul(int N, int *C, short *A, short *B) {
> > > > int i, j;
> > > > for (i = 0; i < N; i++) {
> > > > C[i] = 0; // Will be transformed to __builtin_memset
> > > > for (j = 0; j < N; j++) {
> > > > C[i] += (int)A[i * N + j] * (int)B[j];
> > > > }
> > > > }
> > > > }
> > > >
> > > > If I compile the case with -O2 -fno-tree-loop-distribute-patterns, the store
> > > > operation 'C[i] = 0' can be eliminated by dead store elimination (dse3). But
> > > > without -fno-tree-loop-distribute-patterns, it will be transformed to memset
> > > > by loop distribution (ldist) because ldist executes before dse3. Finally the
> > > > memset will not be eliminated.
> > > >
> > > > Another point is if there are other operations in the same level loop as the
> > > > store operation, is it really beneficial to do loop distribution and then
> > > > convert to builtin function?
> > >
> > > Sure, it shows a cost modeling issue given that usually loop distribution
> > > merges partitions which touch the same memory stream (but IIRC maybe only
> > > for loads). But more to the point we're missing to eliminate the dead store
> > > which should be appearant at least after PRE - LIM2 applied store motion
> > > but only PRE elides the resulting load of C[i]. Usually DCE and DSE come in
> > > pairs but after PRE we have DCE, CDDCE w/o accompaning DSE only with the
> > > next DSE only happening after loop distribution.
> > >
> > > Which means we should eventually do
> > >
> > > diff --git a/gcc/passes.def b/gcc/passes.def
> > > index e9ed3c7bc57..be3a9becde0 100644
> > > --- a/gcc/passes.def
> > > +++ b/gcc/passes.def
> > > @@ -254,6 +254,7 @@ along with GCC; see the file COPYING3. If not see
> > > NEXT_PASS (pass_sancov);
> > > NEXT_PASS (pass_asan);
> > > NEXT_PASS (pass_tsan);
> > > + NEXT_PASS (pass_dse);
> > > NEXT_PASS (pass_dce);
> > > /* Pass group that runs when 1) enabled, 2) there are loops
> > > in the function. Make sure to run pass_fix_loops before
> >
> > Yes, doing DSE before ldist is a simple and effective way.
> > This patch has been verified to be work on coremark. Not only improved
> > performance, but also code size.
>
> The test case gcc.dg/tree-ssa/ldist-33.c is failure after I added DSE.
>
> /* { dg-do compile { target size32plus } } */
> /* { dg-options "-O2 -ftree-loop-distribution -ftree-loop-distribute-patterns
> -fdump-tree-ldist-details" } */
>
> #define N (1024)
> double a[N][N], b[N][N], c[N][N];
>
> void
> foo (void)
> {
> unsigned i, j, k;
>
> for (i = 0; i < N; ++i)
> for (j = 0; j < N; ++j)
> {
> c[i][j] = 0.0;
> for (k = 0; k < N; ++k)
> c[i][j] += a[i][k] * b[k][j];
> }
> }
>
> /* { dg-final { scan-tree-dump "Loop nest . distributed: split to 1 loops and 1
> library" "ldist" } } */
>
> It is similar to the example I showed earlier. DSE eliminated 'c[i][j] = 0.0'
> so no loop will be split. My question is how to handle this test case? Add
> -fno-tree-dse into dg-options, modify this test case, delete this test case, or
> others.
I'd say disable store-motion with a comment (-fno-tree-loop-im, we might
also finally add a separate switch to control the store-motion part of
GIMPLE invariant motion). I think
the testcase should show we can recognize the memset in a non-innermost
loop (IIRC the above mimics what bwaves does).
next prev parent reply other threads:[~2021-03-03 8:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-09 6:06 [Bug tree-optimization/94092] New: " bina2374 at gmail dot com
2020-03-09 6:17 ` [Bug tree-optimization/94092] " pinskia at gcc dot gnu.org
2020-03-09 6:29 ` pinskia at gcc dot gnu.org
2020-03-09 6:30 ` pinskia at gcc dot gnu.org
2020-03-09 7:37 ` glisse at gcc dot gnu.org
2020-03-09 9:48 ` rguenth at gcc dot gnu.org
2021-02-19 8:05 ` aoliva at gcc dot gnu.org
2021-02-23 23:57 ` wilson at gcc dot gnu.org
2021-02-24 7:43 ` rguenth at gcc dot gnu.org
2021-02-24 9:05 ` bina2374 at gmail dot com
2021-02-24 9:20 ` rguenth at gcc dot gnu.org
2021-02-26 6:35 ` bina2374 at gmail dot com
2021-03-03 6:30 ` bina2374 at gmail dot com
2021-03-03 8:03 ` rguenther at suse dot de [this message]
2021-04-29 4:24 ` aoliva at gcc dot gnu.org
2021-04-30 14:38 ` law at gcc dot gnu.org
2021-05-03 6:28 ` rguenther at suse dot de
2021-05-04 12:26 ` rguenth at gcc dot gnu.org
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=bug-94092-4-TCkcBCXimi@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/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).