public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Manolis Tsamis <manolis.tsamis@vrull.eu>
To: Philipp Tomsich <philipp.tomsich@vrull.eu>
Cc: "Jeff Law" <jeffreyalaw@gmail.com>,
	gcc-patches@gcc.gnu.org, "Richard Biener" <rguenther@suse.de>,
	"Christoph Müllner" <christoph.muellner@vrull.eu>,
	"Jiangning Liu" <jiangning.liu@amperecomputing.com>,
	"Jakub Jelinek" <jakub@redhat.com>,
	"Andrew Pinski" <quic_apinski@quicinc.com>
Subject: Re: [PATCH v2] Target-independent store forwarding avoidance.
Date: Wed, 12 Jun 2024 16:02:29 +0300	[thread overview]
Message-ID: <CAM3yNXpw-2z5vkzzwLRch=LOo=2cyL1O7qQpEZnYXp1GOv9Vrw@mail.gmail.com> (raw)
In-Reply-To: <CAAeLtUCThU562S-toXOyz4BOSaMM39=fGuuGQ48G60viHxu1og@mail.gmail.com>

On Mon, Jun 10, 2024 at 9:27 PM Philipp Tomsich
<philipp.tomsich@vrull.eu> wrote:
>
> On Mon, 10 Jun 2024 at 20:03, Jeff Law <jeffreyalaw@gmail.com> wrote:
> >
> >
> >
> > On 6/10/24 1:55 AM, Manolis Tsamis wrote:
> >
> > >>
> > > There was an older submission of a load-pair specific pass but this is
> > > a complete reimplementation and indeed significantly more general.
> > > Apart from being target independant, it addresses a number of
> > > important restrictions and can handle multiple store forwardings per
> > > load.
> > > It should be noted that it cannot handle the load-pair cases as these
> > > need special handling, but that's something we're planning to do in
> > > the future by reusing this infrastructure.
> > ACK.  Thanks for the additional background.
> >
> >
> > >
> > >>
> > >>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> > >>> index 4e8967fd8ab..c769744d178 100644
> > >>> --- a/gcc/doc/invoke.texi
> > >>> +++ b/gcc/doc/invoke.texi
> > >>> @@ -12657,6 +12657,15 @@ loop unrolling.
> > >>>    This option is enabled by default at optimization levels @option{-O1},
> > >>>    @option{-O2}, @option{-O3}, @option{-Os}.
> > >>>
> > >>> +@opindex favoid-store-forwarding
> > >>> +@item -favoid-store-forwarding
> > >>> +@itemx -fno-avoid-store-forwarding
> > >>> +Many CPUs will stall for many cycles when a load partially depends on previous
> > >>> +smaller stores.  This pass tries to detect such cases and avoid the penalty by
> > >>> +changing the order of the load and store and then fixing up the loaded value.
> > >>> +
> > >>> +Disabled by default.
> > >> Is there any particular reason why this would be off by default at -O1
> > >> or higher?  It would seem to me that on modern cores that this
> > >> transformation should easily be a win.  Even on an old in-order core,
> > >> avoiding the load with the bit insert is likely profitable, just not as
> > >> much so.
> > >>
> > > I don't have a strong opinion for that but I believe Richard's
> > > suggestion to decide this on a per-target basis also makes a lot of
> > > sense.
> > > Deciding whether the transformation is profitable is tightly tied to
> > > the architecture in question (i.e. how large the stall is and what
> > > sort of bit-insert instructions are available).
> > > In order to make this more widely applicable, I think we'll need a
> > > target hook that decides in which case the forwarded stores incur a
> > > penalty and thus the transformation makes sense.
> > You and Richi are probably right.   I'm not a big fan of passes being
> > enabled/disabled on particular targets, but it may make sense here.
> >
> >
> >
> > > Afaik, for each CPU there may be cases that store forwarding is
> > > handled efficiently.
> > Absolutely.   But forwarding from a smaller store to a wider load is
> > painful from a hardware standpoint and if we can avoid it from a codegen
> > standpoint, we should.
>
> This change is what I briefly hinted as "the complete solution" that
> we had on the drawing board when we briefly talked last November in
> Santa Clara.
>
> > Did y'all look at spec2017 at all for this patch?  I've got our hardware
> > guys to expose a signal for this case so that we can (in a month or so)
> > get some hard data on how often it's happening in spec2017 and evaluate
> > how this patch helps the most affected workloads.  But if y'all already
> > have some data we can use it as a starting point.
>
>  We have looked at all of SPEC2017, especially for coverage (i.e.,
> making sure we see a significant number of uses of the transformation)
> and correctness.  The gcc_r and parest_r components triggered in a
> number of "interesting" ways (e.g., motivating the case of
> load-elimination).  If it helps, we could share the statistics for how
> often the pass triggers on compiling each of the SPEC2017 components?
>
Below is a table with 1) the number of successful
store-forwarding-avoidance transformations and 2) the number of these
where the load was also eliminated.
This is SPEC2017 intrate and fprate; the omitted benchmarks in each
case have zero transformations.

Following Richard's comment I did two runs: One with the pass placed
just after cse1 (this patch) and one with it placed after sched1
(Richard's suggestion). I see an increased number of transformations
after sched1 and also in some testcases we get improved code
generation so it looks promising. The original motivation was that
placing this early will enable subsequent passes to optimize the
transformed code, but it looks like this is not a major issue and the
load/store placement it more important.

I plan to follow up and provide some rough performance metrics and
example assembly code of the transformation for these benchmarks.
I also tried increasing the maximum distance from 10 to 15 and so only
a small increase in transformation count. From what I've seen most
cases that we care about are usually close.

The data (benchmark, # transformed, # load elimination):

After cse1:
  500: 32 1
  502: 89 9
  510: 517 409
  511: 12 1
  520: 1 0
  521: 4 1
  525: 51 1
  526: 46 11
  557: 1 1

After sched1:
  500: 45 13
  502: 172 33
  507: 23 23
  510: 544 427
  511: 41 29
  520: 119 26
  521: 19 11
  523: 4 4
  525: 129 44
  526: 120 70
  531: 1 1
  538: 30 18
  541: 2 2
  557: 4 4

Note: ran on AArch64 with -O3 -mcpu=neoverse-n1 -flto=32.

Thanks,
Manolis

> Philipp.

  parent reply	other threads:[~2024-06-12 13:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06 10:10 Manolis Tsamis
2024-06-07 22:31 ` Jeff Law
2024-06-09 14:29   ` Jeff Law
2024-06-10  8:03     ` Manolis Tsamis
2024-06-13 11:40     ` Manolis Tsamis
2024-06-13 13:59       ` Jeff Law
2024-06-10  6:26   ` Richard Biener
2024-06-10  7:55   ` Manolis Tsamis
2024-06-10 18:03     ` Jeff Law
2024-06-10 18:27       ` Philipp Tomsich
2024-06-10 18:37         ` Jeff Law
2024-06-12 13:02         ` Manolis Tsamis [this message]
2024-06-11  7:22       ` Richard Biener
2024-06-11 13:37         ` Jeff Law
2024-06-11 13:52           ` Philipp Tomsich
2024-06-11 14:18             ` Jeff Law
2024-06-12  6:47               ` Richard Biener
2024-06-12 14:18                 ` Jeff Law

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='CAM3yNXpw-2z5vkzzwLRch=LOo=2cyL1O7qQpEZnYXp1GOv9Vrw@mail.gmail.com' \
    --to=manolis.tsamis@vrull.eu \
    --cc=christoph.muellner@vrull.eu \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jeffreyalaw@gmail.com \
    --cc=jiangning.liu@amperecomputing.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=quic_apinski@quicinc.com \
    --cc=rguenther@suse.de \
    /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).