All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH] experimental: code sinking
Date: Fri, 4 Dec 2020 10:15:30 -0800	[thread overview]
Message-ID: <CAHk-=wh15fTgsd+D7_goVzZY3NFPVke8ENTPtUdu5HYi2Pkgbw@mail.gmail.com> (raw)
In-Reply-To: <20201204174502.5wkqf7xashx2poet@ltop.local>

On Fri, Dec 4, 2020 at 9:45 AM Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
>
> > There might be cases where instruction sinking makes sense even
> > outside the "can we empty this bb entirely" issue. Not that I can
> > think of any, but I wonder if this could be used to actually shrink
> > liveness regions (if both the inputs to the sunk instruction are live
> > _anyway_ at the target, then sinking the instruction should actually
> > improve liveness in general, for example).
>
> I don't think I understand this. In the case of an UNOP, sinking it
> increase the liveness and decrease the liveness of the output, so
> it should not matter much.

Right. The UNOP case should be a no-op from a liveness perspective, but:

> In the case of an BINOP or select, sinking
> it will decrease the liveness of the unique output but increase the
> liveness of the inputs. So, it seems to me that sinking would
> globally increase the liveness (contrary to moving up instructions).
> Am I missing something?

No, moving a binop could actually *shrink* liveness under the right
circumstances - namely when the sources of the binop are live
regardless.

Completely stupid example that makes no sense, and only exists to
illustrate the issue:

    int diff(int x, int y);
    int fn2(int x, int y, int sum, int diff);

    int test(int x, int y)
    {
        int sum = x+y;

        return fn2(x, y, sum, diff(x,y));
    }

which generates

    add.32      %r3 <- %arg1, %arg2
    call.32     %r9 <- fn1, %arg1, %arg2
    call.32     %r10 <- fn2, %arg1, %arg2, %r3, %r9
    ret.32      %r10

but it would actually improve liveness if that "add" was moved down -
because even though it "expands" the liveness of %arg1/arg2 by moving
the use of those down, both of those argument pseudos have later uses
_anyway_. So that expansion of liveness is a non-issue.

Instead, it shrinks the liveness region of %r3. Ergo, it actually
shrinks liveness region in the big picture.

Now, the above stupid example is one single bb, so in that sense it's
not really relevant for your inter-bb movement, but that doesn't
actually change the argument at all. Insert a conditional in there to
get a multi-bb case.

              Linus

  reply	other threads:[~2020-12-04 18:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-04 16:33 [PATCH] experimental: code sinking Luc Van Oostenryck
2020-12-04 17:13 ` Linus Torvalds
2020-12-04 17:45   ` Luc Van Oostenryck
2020-12-04 18:15     ` Linus Torvalds [this message]
2020-12-04 20:23       ` Luc Van Oostenryck

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='CAHk-=wh15fTgsd+D7_goVzZY3NFPVke8ENTPtUdu5HYi2Pkgbw@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.