public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Jeff Law <jeffreyalaw@gmail.com>
Cc: Ajit Agarwal <aagarwa1@linux.ibm.com>,
	Peter Bergner <bergner@linux.ibm.com>,
	 "Kewen.Lin" <linkw@linux.ibm.com>,
	Michael Meissner <meissner@linux.ibm.com>,
	 Segher Boessenkool <segher@kernel.crashing.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	 David Edelsohn <dje.gcc@gmail.com>
Subject: Re: [PATCH V12]: Improve code sinking pass
Date: Thu, 14 Mar 2024 08:43:02 +0100	[thread overview]
Message-ID: <CAFiYyc1wOni3KLgux5Z8eH=dhzeiYQFKQbk-T5xeNxx6vmnykg@mail.gmail.com> (raw)
In-Reply-To: <4b5761e7-9e03-4d81-8806-732381ce4309@gmail.com>

On Wed, Mar 13, 2024 at 9:27 PM Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
>
> On 3/13/24 4:22 AM, Richard Biener wrote:
>
> >
> > ... this hunk is OK (please test and split it out separatley).  In the spirit of
> > moving the stmt the least amount (in this case not schedule it within the
> > basic-block).  In the same spirit one would choose an earlier basic-block
> > but only if the old choosen one post-dominates that, dominance isn't
> > a good criteria since you'd move it where the computation might not be
> > needed.  A practical testcase would be
> >
> >    tem = a + b;
> >    if (foo)
> >      bar ();
> >    tem2 = tem + d;
> >
> > where we at the moment would sink 'tem = a+ b' to the block containing
> > 'tem2 = tem + d' not reducing the number of evaluations (of course bar()
> > might not return, but that's a minor detail).  Code motion like that should
> > be subject to register-pressure considerations which we do not estimate
> > here at all.  So it could be argued we shouldn't perform any sinking here.
> Agreed.  This looks more like a scheduling and register-pressure issue
> rather than a classic sinking issue.
>
> Sinking is supposed to be moving code to lesser executed points.  In the
> case above, the only way sinking into the tem2 = block would be if bar()
> doesn't return.  It just doesn't make sense to me from a sinking standpoint.
>
> The block execution data generally prevents this kind of gratuitous
> movement.
>
> I actually evaluated our sinking code several years ago against an
> implementation of Click's algorithm.  In general they were quite
> comparable in terms of selecting an "optimal" block from an execution
> standpoint.  There were a couple of fixes that were added to our
> implementation at that time, but again, generally we were picking
> sensible blocks.
>
>
> >
> > A good first-order heuristic would be to avoid the scheduling
> > when the number of non-virtual SSA uses on the stmt to be moved is bigger
> > than one.  For zero we reduce the lifetime of the def.  For one we're not
> > making things worse.  For more uses it depends on whether we're moving
> > within the lifetime of the uses and it becomes a global problem (we're
> > greedily moving dependent statements, so we even get "local global" wrong
> > then).
> >
> > That said, changing will cause regressions, given both before and after
> > is somewhat ad-hoc it's hard to argue one is more correct than the other.
> >
> > IMO scheduling should be left to a stmt scheduler on GIMPLE
> > (which we don't have).
> Click's work can function as a statement scheduler, though I'm not
> convinced it's actually a good one.  Essentially most statements are
> conceptually disassociated from their blocks, then re-scheduled by
> visiting defining statements of "pinned" instructions.  That model is
> mostly for driving redundancy elimination.  Scheduling is just a side
> effect.
>
>
>
> Bernd had a statement scheduler for gimple years ago, but it was
> somewhat controversial at the time and never moved forward enough to get
> integrated.  IIRC it ran just before or just after TER and its primary
> objective was to avoid some of the pathological cases that ultimately
> result in significant spilling after we're done with the bulk of the RTL
> pipeline.

Yeah, the most difficult thing with scheduling on GIMPLE is the interaction
with TER.  TER does have some "scheduling boundaries" it respects
(I'd have to look them up), so GIMPLE scheduling that only looks at
scheduling across such boundaries might be useful.

Richard.

      reply	other threads:[~2024-03-14  7:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13  9:02 Ajit Agarwal
2024-03-13 10:22 ` Richard Biener
2024-03-13 20:27   ` Jeff Law
2024-03-14  7:43     ` Richard Biener [this message]

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='CAFiYyc1wOni3KLgux5Z8eH=dhzeiYQFKQbk-T5xeNxx6vmnykg@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=aagarwa1@linux.ibm.com \
    --cc=bergner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=linkw@linux.ibm.com \
    --cc=meissner@linux.ibm.com \
    --cc=segher@kernel.crashing.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).