public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Gary Oblock <goblock@marvell.com>, "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: RFC on a new optimization
Date: Mon, 01 Jul 2019 22:08:00 -0000	[thread overview]
Message-ID: <8ff1dafa-9f61-8f03-e09f-018c30e87001@redhat.com> (raw)
In-Reply-To: <DM6PR18MB3290D566876B1D064CC6382BB9F90@DM6PR18MB3290.namprd18.prod.outlook.com>

On 7/1/19 3:58 PM, Gary Oblock wrote:
> I've been looking at trying to optimize the performance of code for
> programs that use functions like qsort where a function is passed the
> name of a function and some constant parameter(s).
> 
> The function qsort itself is an excellent example of what I'm trying to show
> what I want to do, except for being in a library, so please ignore
> that while I proceed assuming that that qsort is not in a library.  In
> qsort the user passes in a size of the array elements and comparison
> function name in addition to the location of the array to be sorted. I
> noticed that for a given call site that the first two are always the
> same so why not create a specialized version of qsort that eliminates
> them and internally uses a constant value for the size parameter and
> does a direct call instead of an indirect call. The later lets the
> comparison function code be inlined.
> 
> This seems to me to be a very useful optimization where heavy use is
> made of this programming idiom. I saw a 30%+ overall improvement when
> I specialized a function like this by hand in an application.
> 
> My question is does anything inside gcc do something similar? I don't
> want to reinvent the wheel and I want to do something that plays
> nicely with the rest of gcc so it makes it into real world. Note, I
> should mention that I'm an experienced compiler developed and I'm
> planning on adding this optimization unless it's obvious from the
> ensuing discussion that either it's a bad idea or that it's a matter
> of simply tweaking gcc a bit to get this optimization to occur.
Jan is the expert in this space, but yes, GCC has devirtualization and
function specialization.  See ipa-devirt.c and ipa-cp.c  You can use the
-fdump-ipa-all-details option to produce debugging dumps for the IPA
passes.  THat might help guide you a bit.


jeff

  reply	other threads:[~2019-07-01 22:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-01 21:58 Gary Oblock
2019-07-01 22:08 ` Jeff Law [this message]
2019-07-01 23:02   ` [EXT] " Gary Oblock
2019-07-01 23:05     ` Jeff Law
2019-07-02  9:46 ` Richard Biener
2019-07-02 10:02   ` Martin Jambor
2019-07-02 18:04   ` [EXT] " Gary Oblock

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=8ff1dafa-9f61-8f03-e09f-018c30e87001@redhat.com \
    --to=law@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=goblock@marvell.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).