public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Erick Ochoa <eochoa@gcc.gnu.org>
Cc: GCC Development <gcc@gcc.gnu.org>
Subject: Re: Creating a wrapper around a function at compile time
Date: Thu, 14 Jul 2022 15:50:43 +0200	[thread overview]
Message-ID: <CAFiYyc0tfFuWUk9G0dt_NakFtR3VBjkEun2Ngv49vjzsgowCew@mail.gmail.com> (raw)
In-Reply-To: <CAJ_nqzgonkU=300mtw3N1ucJNmYSRyQ556HUdiby-fLeDSiTOQ@mail.gmail.com>

On Thu, Jul 14, 2022 at 3:42 PM Erick Ochoa <eochoa@gcc.gnu.org> wrote:
>
> Hi Richard,
>
>
>> >
>> > So instead of wrapping the function why not transform the original function
>> > to have a prologue doing a runtime check for the compile-time specialized
>> > versions and perform tail-calls to them?
>> >
>> > What I'm missing is who would call mul_test_param in your case?
>
>
> The idea is that all callsites to mul may call instead mul_test_param or only those for which there is no known compile time constant. If we had some more information about the distribution of the parameter values at runtime, then we could even choose not to use the wrapper.
>
>>
>> Following your variant more closely would be doing value profiling
>> of function parameters and then "speculative IPA-CP".
>
>
> Yes, the idea of doing value profiling on function parameters certainly fits this very well. I refrained from calling it "speculative IPA-CP" and instead called it specialization with a parameter test but the idea I think is the same. However, the main difference between "speculative IPA-CP" and this idea is that (if I understand correctly how speculative IPA-CP works) is that instead of changing the callsite C to the following version:
>
> C: mul_test_param (c, d);
>
> speculative IPA-CP will have the transformation
>
> C: if (a == 2) mul.constprop1 (a)
>     else if (a == 4) mul.constprop2 (a)
>     else mul (a, b)
>
> Which depending on how many non compile-time constant callsites there are, will increase the size of the binary. That's why I prefer the wrapper around the function. But this would be essentially inlining the wrapper.

With a value-profile it would be per call site and IPA-CP can use that
to direct the cloning.  I'm not sure how many
values a value histogram can track reliably here.

>
> As of now, the only "speculative IPA-CP" that I've seen is the speculation on the target of the indirect edge. I could look into exactly how this mechanism works to try to instead speculate on an arbitrary argument. Do you think that would be a good first step instead of creating a wrapper and replacing the edges to the wrapper?

  reply	other threads:[~2022-07-14 13:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14 12:38 Erick Ochoa
2022-07-14 13:27 ` Richard Biener
2022-07-14 13:29   ` Richard Biener
2022-07-14 13:46     ` Erick Ochoa
2022-07-14 13:50       ` Richard Biener [this message]
2022-07-14 14:08         ` Erick Ochoa
2022-07-14 14:10           ` Martin Liška
2022-07-14 14:25             ` Erick Ochoa
2022-07-15  8:10               ` Martin Liška
2022-07-15  8:33                 ` Erick Ochoa

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=CAFiYyc0tfFuWUk9G0dt_NakFtR3VBjkEun2Ngv49vjzsgowCew@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=eochoa@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    /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).