This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lemburg
Recipients arhadthedev, gdr@garethrees.org, lemburg, mark.dickinson, rhettinger, vstinner
Date 2021-11-15.09:22:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <6688383a-5bfc-8976-95f5-21f59589918a@egenix.com>
In-reply-to <1636962896.35.0.298441061317.issue45476@roundup.psfhosted.org>
Content
On 15.11.2021 08:54, Oleg Iarygin wrote:
> 
> Oleg Iarygin <oleg@arhadthedev.net> added the comment:
> 
> Marc-Andre:
>> Inlining is something that is completely under the control of the
> used compilers. Compilers are free to not inline function marked for
> inlining [...]
> 
> I checked the following C snippet on gcc.godbolt.org using GCC 4.1.2 and Clang 3.0.0 with <no flags>/-O0/-O1/-Os, and both compilers inline a function marked as static inline:
> 
>     static inline int foo(int a)
>     {
>         return a * 2;
>     }
> 
>     int bar(int a)
>     {
>         return foo(a) < 0;
>     }
> 
> So even with -O0, GCC from 2007 and Clang from 2011 perform inlining. Though, old versions of CLang leave a dangling original copy of foo for some reason. I hope a linker removes it later.

That's a great website :-) Thanks for sharing.

However, even with x86-64 gcc 11.2, I get assembler which does not inline
foo() without compiler options or with -O0: https://gcc.godbolt.org/z/oh6qnffh7

Only with -O1, the site reports inlining foo().

> As for other compilers, I believe that if somebody specifies -O0, that person has a sound reason to do so (like per-line debugging, building precise flame graphs, or other specific scenario where execution performance does not matter), so inlining interferes here anyway.

Sure, but my point was a different one: even with higher optimization
levels, the compiler can decide whether or not to inline. We expect
the compiler to inline, but cannot be sure.

With macros the compiler has no choice and we are in control and even
when using -O0, you will still want e.g. Py_INCREF() and Py_DECREF()
inlined.
History
Date User Action Args
2021-11-15 09:22:59lemburgsetrecipients: + lemburg, rhettinger, mark.dickinson, vstinner, gdr@garethrees.org, arhadthedev
2021-11-15 09:22:59lemburglinkissue45476 messages
2021-11-15 09:22:59lemburgcreate