This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: question about inlining
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: gcc at gcc dot gnu dot org,Martin Sebor <msebor at gmail dot com>,GCC Mailing List <gcc at gcc dot gnu dot org>
- Date: Wed, 06 Dec 2017 20:11:13 +0100
- Subject: Re: question about inlining
- Authentication-results: sourceware.org; auth=none
- References: <e6d88ffd-069f-ba21-9a5c-b3e78398cbb8@gmail.com>
On December 6, 2017 6:38:11 PM GMT+01:00, Martin Sebor <msebor@gmail.com> wrote:
>While testing a libstdc++ patch that relies on inlining to
>expose a GCC limitation I noticed that the same member function
>of a class template is inlined into one function in the test but
>not into the other, even though it is inlined into each if each
>is compiled separately (i.e., in a file on its own).
>
>I wasn't aware that inlining decisions made in one function could
>affect those in another, or in the whole file. Is that expected?
>And if yes, what's the rationale?
>
>Here's a simplified test case. When compiled with -O2 or -O3
>and either just -DFOO or just -DBAR, the call to vector::resize()
>and all the functions called from it, including (crucially)
>vector::_M_default_append, are inlined. But when compiled with
>-DFOO -DBAR _M_default_append is not inlined. With a somewhat
>more involved test case I've also seen the first call inlined
>but not the second, which was also surprising to me.
There are unit and function growth limits that can be hit.
> #include <vector>
>
> void sink (std::vector<int>&);
>
> #if FOO
> void foo (unsigned n)
> {
> std::vector<int> a;
> a.resize (n);
> sink (a);
> }
> #endif
>
> #if BAR
> void bar (unsigned long n)
> {
> std::vector<int> a;
> a.resize (n);
> sink (a);
> }
> #endif
>
>Thanks
>Martin