* Function call inlining
@ 2015-08-27 15:34 Matwey V. Kornilov
2015-08-28 7:59 ` Andrew Haley
0 siblings, 1 reply; 3+ messages in thread
From: Matwey V. Kornilov @ 2015-08-27 15:34 UTC (permalink / raw)
To: gcc-help
Hello,
Please consider the following code from the SO:
http://stackoverflow.com/a/32237033/1879547
template<class Ret, class T, class Func, int... Is>
auto apply(T&& p, int index, Func func, seq<Is...>) -> Ret
{
using FT = Ret(T&&, Func);
static constexpr FT* arr[] = { &apply_one<Ret, Is, T&&, Func>... };
return arr[index](std::forward<T>(p), func);
}
I use gcc-4.8.2 and see that arr[index](std::forward<T>(p), func) call
is not inlined.
The question here is the following. All function pointers are known at
compile time. So, why don't expand this code into analogous to the
following?
switch(index) {
case 0:
// inline arr[0]
break;
case 1:
// inline arr[1]
// etc...
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Function call inlining
2015-08-27 15:34 Function call inlining Matwey V. Kornilov
@ 2015-08-28 7:59 ` Andrew Haley
2015-08-28 8:05 ` Matwey V. Kornilov
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Haley @ 2015-08-28 7:59 UTC (permalink / raw)
To: Matwey V. Kornilov, gcc-help
On 08/27/2015 04:34 PM, Matwey V. Kornilov wrote:
> I use gcc-4.8.2 and see that arr[index](std::forward<T>(p), func) call
> is not inlined.
> The question here is the following. All function pointers are known at
> compile time. So, why don't expand this code into analogous to the
> following?
I suspect that no-one has explained because no-one understands why
anyone would want to make such an "optimization".
Andrew.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Function call inlining
2015-08-28 7:59 ` Andrew Haley
@ 2015-08-28 8:05 ` Matwey V. Kornilov
0 siblings, 0 replies; 3+ messages in thread
From: Matwey V. Kornilov @ 2015-08-28 8:05 UTC (permalink / raw)
To: Andrew Haley; +Cc: gcc-help
2015-08-28 10:59 GMT+03:00 Andrew Haley <aph@redhat.com>:
> On 08/27/2015 04:34 PM, Matwey V. Kornilov wrote:
>> I use gcc-4.8.2 and see that arr[index](std::forward<T>(p), func) call
>> is not inlined.
>> The question here is the following. All function pointers are known at
>> compile time. So, why don't expand this code into analogous to the
>> following?
>
> I suspect that no-one has explained because no-one understands why
> anyone would want to make such an "optimization".
>
The question arised from here:
http://stackoverflow.com/questions/32235855/
Moreover, clang does this kind of optimization:
http://goo.gl/jnY5yx
--
With best regards,
Matwey V. Kornilov
http://blog.matwey.name
xmpp://0x2207@jabber.ru
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-28 8:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-27 15:34 Function call inlining Matwey V. Kornilov
2015-08-28 7:59 ` Andrew Haley
2015-08-28 8:05 ` Matwey V. Kornilov
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).