public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Barak A. Pearlmutter" <barak@cs.nuim.ie>
To: Rask Ingemann Lambertsen <rask@sygehus.dk>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Bizarrely Poor Code from Bizarre Machine-Generated C Sources
Date: Mon, 28 May 2007 07:23:00 -0000	[thread overview]
Message-ID: <E1HsQHZ-0006eD-SN@localhost> (raw)
In-Reply-To: <20070527180509.GX5690@sygehus.dk>

Thanks for the hints.  I really appreciate the advice, and this access
to the secrets of the GCC initiate.

Hope you don't mind if I ask some follow-up questions.

> $ for i in *.s; do echo -n "${i}: "; grep -F -e memcpy ${i} | wc --lines; done

Yup: we had also noticed the zillions of calls to memcpy with static
arguments.  This is part of what I meant by "unnecessary data
shuffling".  Is there some way to tell GCC that it isn't worth calling
memcpy to copy such short structures?  If GCC did the copying using
explicit assembly code, it would probably be able to notice a host of
shuffling reduction opportunities using things like peephole
optimization.  At least, that was our impression from looking at the
generated code.

> The way you are using structures forces GCC to copy data around.
> ...  Change structures into scalar variables ... GCC has more
> freedom to place scalar variables than structures.

Some copying is of course unavoidable, especially at procedure call
boundaries.

But none of the structures are on the heap (no malloc) and we never
take any addresses, so in theory they could be held in registers and
kept in fragmented representations and that sort of thing.  I do not
know if GCC can do that, or if there's any way to tell it to.

We could re-jigger our back end to generate FORTRAN instead of C and
use GCC's FORTRAN stuff, maybe that would help?

> Unless you somehow manage to inline the whole program into main(), I
> don't see how it can be any different.

That would certainly be ideal!  (Modulo cycles in the call graph that
contain a non-tail-recursive link; I do not believe there is any such
cycle in this particular hunk of C code.)  Perhaps there some way to
tell GCC that when I declare a procedure "inline", I really mean it?
As you can see, our compiler goes to some trouble to mark which
procedures it thinks should always be inlined versus which should be
the C compiler's judgement call.

> You will definitely want a lot of inlining for this sort of code, so
> at least use -O3, but perhaps play with the inlining parameters too.

Right; -O3 didn't make any qualitative difference.  (I certainly tried
that before posting.)  I do see a whole bunch of inline-related
parameters in the GCC documentation, but it is not clear which I
should tweaked.  I tried -O3 -flinline-limit=60000 (default 600) but
even that doesn't make any qualitative difference.

					Cheers & Thanks,

					--Barak.

  reply	other threads:[~2007-05-27 21:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-27 15:11 Barak A. Pearlmutter
2007-05-27 18:22 ` Rask Ingemann Lambertsen
2007-05-28  7:23   ` Barak A. Pearlmutter [this message]
2007-05-28  9:42     ` Mattias Engdegård
2007-05-28 11:26     ` Rask Ingemann Lambertsen
2007-05-29 16:10 Barak A. Pearlmutter
2007-05-29 23:39 ` Andrew Haley

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=E1HsQHZ-0006eD-SN@localhost \
    --to=barak@cs.nuim.ie \
    --cc=gcc-help@gcc.gnu.org \
    --cc=rask@sygehus.dk \
    /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).