Thread overview
Inlined functions and their original bodies - bloat
Jul 09, 2023
Cecil Ward
Jul 09, 2023
Cecil Ward
Jul 09, 2023
Adam D Ruppe
Jul 10, 2023
kinke
July 09, 2023
I have a program where the various routines are all marked pragma( inline, true ). The compiler obeys this but the LDC and GDC compilers still compile the function bodies even though the bodies are not needed as they are supposed to be ‘private’ to the module, explicitly marked as such, hoping that that is like static in C. There are no pointers to the routines, so no need for the bodies because of any indirect calls. Is there a way to control this code bloat in LDC / GDC ? Using the godbolt compiler explorer with LDC and GDC I can indeed see that the code is being inlined. Does this count as a compiler performance-type bug?
July 09, 2023
On Sunday, 9 July 2023 at 18:04:13 UTC, Cecil Ward wrote:
> I have a program where the various routines are all marked pragma( inline, true ). The compiler obeys this but the LDC and GDC compilers still compile the function bodies even though the bodies are not needed as they are supposed to be ‘private’ to the module, explicitly marked as such, hoping that that is like static in C. There are no pointers to the routines, so no need for the bodies because of any indirect calls. Is there a way to control this code bloat in LDC / GDC ? Using the godbolt compiler explorer with LDC and GDC I can indeed see that the code is being inlined. Does this count as a compiler performance-type bug?

This is with full -O3 optimisation and -release / -frelease for LDC and GDC respectively.
July 09, 2023
On Sunday, 9 July 2023 at 18:05:48 UTC, Cecil Ward wrote:
> This is with full -O3 optimisation

try -fvisibility=hidden

-release sux btw

July 10, 2023
The 'bloat' is usually gotten rid of by the linker if really unreferenced in the binary being linked.

There's a little trick to make sure the function is *always* inlined, across modules too, allowing to suppress the then guaranteed unused function symbol - converting it to a function literal. See https://github.com/ldc-developers/ldc/issues/2968#issuecomment-1628615699.