public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com
Subject: Re: Mostly rewrite genrecog
Date: Tue, 28 Apr 2015 23:18:00 -0000	[thread overview]
Message-ID: <554013F8.9050300@redhat.com> (raw)
In-Reply-To: <87egn5yis1.fsf@e105548-lin.cambridge.arm.com>

On 04/27/2015 04:20 AM, Richard Sandiford wrote:
> I think it's been the case for a while that parallel builds of GCC tend
> to serialise around the compilation of insn-recog.c, especially with
> higher --enable-checking settings.  This patch tries to speed that
> up by replacing most of genrecog with a new algorithm.
>
> I think the main problems with the current code are:
>
> 1. Vector architectures have added lots of new instructions that have
>     a similar shape and differ only in mode, code or unspec number.
>     The current algorithm doesn't have any way of factoring out those
>     similarities.
>
> 2. When matching a particular instruction, the current code examines
>     everything about a SET_DEST before moving on to the SET_SRC.  This has
>     two subproblems:
>
>     2a. The destination of a SET isn't very distinctive.  It's usually
>         just a register_operand, a memory_operand, a nonimmediate_operand
>         or a flags register.  We therefore tend to backtrack to the
>         SET_DEST a lot, oscillating between groups of instructions with
>         the same kind of destination.
>
>     2b. Backtracking through predicate checks is relatively expensive.
>         It would be good to narrow down the "shape" of the instruction
>         first and only then check the predicates.  (The backtracking is
>         expensive in terms of insn-recog.o compile time too, both because
>         we need to copy into argument registers and out of the result
>         register, and because it adds more sites where spills are needed.)
>
> 3. The code keeps one local variable per rtx depth, so it ends up
>     loading the same rtx many times over (mostly when backtracking).
>     This is very expensive in rtl-checking builds because each XEXP
>     includes a code check and a line-specific failure call.
>
>     In principle the idea of having one local variable per depth
>     is good.  But it was originally written that way when all optimisations
>     were done at the rtl level and I imagine each local variable mapped
>     to one pseudo register.  These days the statements that reload the
>     value needed on backtracking lead to many more SSA names and phi
>     statements than you'd get with just a single variable per position
>     (loaded once, so naturally SSA).  There is still the potential benefit
>     of avoiding having sibling rtxes live at once, but fixing (2) above
>     reduces that problem.
>
> Also, the code is all goto-based, which makes it rather hard to step through.
>
> The patch deals with these as follows:
>
> 1. Detect subpatterns that differ only by mode, code and/or integer
>     (e.g. unspec number) and split them out into a common routine.
>
> 2. Match the "shape" of the instruction first, in terms of codes,
>     integers and vector lengths, and only then check the modes, predicates
>     and dups.  When checking the shape, handle SET_SRCs before SET_DESTs.
>     In practice this seems to greatly reduce the amount of backtracking.
>
> 3. Have one local variable per rtx position.  I tested the patch with
>     and without the change and it helped a lot with rtl-checking builds
>     without seeming to affect release builds much either way.
>
> As far as debuggability goes, the new code avoids gotos and just
> uses "natural" control flow.
>
> The headline stat is that a stage 3 --enable-checking=yes,rtl,df
> build of insn-recog.c on my box goes from 7m43s to 2m2s (using the
> same stage 2 compiler).  The corresponding --enable-checking=release
> change is from 49s to 24s (less impressive, as expected).
>
> The patch seems to speed up recog.  E.g. the time taken to build
> fold-const.ii goes from 6.74s before the patch to 6.69s after it;
> not a big speed-up, but reproducible.
[ big snip ]

I don't see anything that makes me think we don't want this :-)

It's interesting to note that the regressions in loadable size of a 
release-checking insn-recog aren't any mainstream ports.  Hell, I'd 
probably claim they're all fringe ports (iq2000, m68k, mcore, 
microblaze, pdp11, rx)


> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-none-eabi.
> Also tested by building the testsuite for each of the targets above
> and making sure there were no assembly differences.  Made sure that no
> objects in spec2k6 changed for aarch64-linux-gnu (except for perlbench
> perl.o and cactusADM datestamp.o, where the differences are timestamps).
> OK to install?
To be very blunt, I'm probably not capable of reviewing the new code. 
You're going to know it best and you should probably own it.

Given your history with gcc and attention to detail, I'm comfortable 
with approving this knowing you'll deal with any issues as they arise.

The one thing I would ask is that you make sure to include the recently 
added matching constraint checking bits in genrecog.  I'm assuming all 
the older sanity checks that have been in genrecog for a longer period 
of time have been kept.

Jeff

  reply	other threads:[~2015-04-28 23:13 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 10:20 Richard Sandiford
2015-04-28 23:18 ` Jeff Law [this message]
2015-04-29 13:59   ` Richard Sandiford
2015-04-29  8:52 ` Eric Botcazou
2015-04-29 13:51   ` Richard Sandiford
2015-04-30 10:44     ` Eric Botcazou
2015-04-30  6:54 ` Bin.Cheng
2015-04-30 11:58   ` Richard Sandiford
2015-04-30  7:17 ` Andreas Schwab
2015-04-30  7:58   ` Richard Sandiford
2015-04-30 12:10     ` Andreas Schwab
2015-04-30 12:33       ` Richard Biener
2015-04-30 16:27         ` Richard Sandiford
2015-05-01 12:42           ` Richard Sandiford
2015-05-01 13:57             ` Jeff Law
2015-05-07  8:59 ` [nvptx] " Thomas Schwinge
2015-05-07  9:14   ` Jakub Jelinek
2015-05-21  8:09     ` Thomas Schwinge
2015-05-21 11:57       ` Bernd Schmidt
2015-05-08  9:10 ` genrecog: Address -Wsign-compare diagnostics (was: Mostly rewrite genrecog) Thomas Schwinge
2015-05-08 14:43   ` genrecog: Address -Wsign-compare diagnostics Richard Sandiford
2015-05-08 18:39   ` Jeff Law
2015-05-16  8:13 ` Mostly rewrite genrecog Andreas Krebbel
2015-05-17 22:05   ` Richard Sandiford
2015-05-22 16:14     ` Andreas Krebbel
2015-05-22 16:32       ` Richard Sandiford
2015-05-29 17:39         ` RFA: Fix mode checks for possibly-constant predicates Richard Sandiford
2015-05-29 19:27           ` Richard Henderson
2015-06-03  7:23             ` Richard Sandiford
2015-06-03  9:39               ` Richard Sandiford

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=554013F8.9050300@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.sandiford@arm.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 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).