From: Richard Biener <richard.guenther@gmail.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: Do not account __builtin_unreachable guards in inliner
Date: Fri, 23 Jun 2023 13:11:00 +0200 [thread overview]
Message-ID: <CAFiYyc1AAPvcXDKVUMDoTbc=0ByVJ9faq8uA+Ki08=fTUfUDig@mail.gmail.com> (raw)
In-Reply-To: <ZJVvvKYDknwJAuYN@kam.mff.cuni.cz>
On Fri, Jun 23, 2023 at 12:11 PM Jan Hubicka <hubicka@ucw.cz> wrote:
>
> > On Mon, Jun 19, 2023 at 12:15 PM Jan Hubicka <hubicka@ucw.cz> wrote:
> > >
> > > > On Mon, Jun 19, 2023 at 9:52 AM Jan Hubicka via Gcc-patches
> > > > <gcc-patches@gcc.gnu.org> wrote:
> > > > >
> > > > > Hi,
> > > > > this was suggested earlier somewhere, but I can not find the thread.
> > > > > C++ has assume attribute that expands int
> > > > > if (conditional)
> > > > > __builtin_unreachable ()
> > > > > We do not want to account the conditional in inline heuristics since
> > > > > we know that it is going to be optimized out.
> > > > >
> > > > > Bootstrapped/regtested x86_64-linux, will commit it later today if
> > > > > thre are no complains.
> > > >
> > > > I think we also had the request to not account the condition feeding
> > > > stmts (if they only feed it and have no side-effects). libstdc++ has
> > > > complex range comparisons here. Also ...
> > >
> > > I was thinking of this: it depends on how smart do we want to get.
> > > We also have dead conditionals guarding clobbers, predicts and other
> > > stuff. In general we can use mark phase of cd-dce telling it to ignore
> > > those statements and then use its resut in the analysis.
> >
> > Hmm, possible but a bit heavy-handed. There's simple_dce_from_worklist
> > which might be a way to do this (of course we cannot use that 1:1). Also
> > then consider
> >
> > a = a + 1;
> > if (a > 10)
> > __builtin_unreachable ();
> > if (a < 5)
> > __builtin_unreachable ();
> >
> > and a has more than one use but both are going away. So indeed a
> > more global analysis would be needed to get the full benefit.
>
> I was looking into simple_dce_from_worklist and if I understand it
> right, it simply walks list of SSA names which probably lost some uses
> by the consuming pass. If they have zero non-debug uses and defining statement has
> no side effects, then they are removed.
>
> I think this is not really fitting the bill here since the example above
> is likely to be common and also if we want one assign filling
> conditional optimized out, we probably want to handle case with multiple
> assignments. What about
> 1) walk function body and see if there are conditionals we know will be
> optimized out (at the begining those can be only those which has one
> arm reaching __bulitin_unreachable
> 2) if there are none, just proceed with fnsummary construction
> 3) if there were some, do non-cd-dce mark stage which will skip those
> dead conditional identified in 1
> and proceed to fnsummary construction with additional bitmap of
> marked stmts.
So you need to feed it with extra info on the optimized out stmts because
as-is it will not remove __builtin_unreachable (). That means you're
doing the find_obviously_necessary_stmts manually, skipping the
conditional and all stmts it controls to the __builtin_unreachable () path?
I also think you want something cheaper than non-cd-dce mark, you also don't
want to bother with stores/loads?
Also when you only do this conditional how do you plan to use the result?
Richard.
>
> This should be cheaper than unconditionally doing cd-dce and should
> handle common cases?
> Honza
next prev parent reply other threads:[~2023-06-23 11:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-19 7:52 Jan Hubicka
2023-06-19 9:01 ` Richard Biener
2023-06-19 10:15 ` Jan Hubicka
2023-06-19 11:30 ` Richard Biener
2023-06-19 11:40 ` Richard Biener
2023-06-23 10:11 ` Jan Hubicka
2023-06-23 11:11 ` Richard Biener [this message]
2023-06-23 13:19 ` Jan Hubicka
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='CAFiYyc1AAPvcXDKVUMDoTbc=0ByVJ9faq8uA+Ki08=fTUfUDig@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
/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).