It is fairly common knowledge that the most powerful tool in a compilers tool-belt is the inlining of functions into their call sites. But what about doing the reverse? If so, is it done? And when? For example given:
void foo(int x)
{
auto y = bar(x);
baz(y);
}
void bop()
{
int x;
auto y = bar(x);
baz(y);
}
Does it ever make sense for the compiler to abstract this out to
void qux(int x)
{
auto y = bar(x);
baz(y);
}
void foo(int x)
{
qux(x);
}
void bop()
{
int x;
qux(x);
}
inlinekeyword is considered a hint that the compiler is permitted to ignore. I remember documentation for one older compiler that listed criteria for a function to be "too complicated to inline" (and one of those criteria was containing conditional statements), and another that treated inlining as an optimisation so would never inline when compiling without optimisation. There is nothing stopping modern compilers from doing similar things (although, presumably, the basis for "too complicated to inline" will have evolved).