On Wednesday, 28 March 2018 at 00:56:29 UTC, kinke wrote:
On Tuesday, 27 March 2018 at 23:59:09 UTC, Rubn wrote:
Just adding a few writeln it isn't able to remove the function
entirely anymore and can't optimize it out.
Well writeln() here involves number -> string formatting, GC,
I/O, template bloat... There are indeed superfluous memcpy's in
your foo() there (although the forward and bar calls are still
inlined), which after a quick glance seem to be LLVM optimizer
shortcomings, the IR emitted by LDC looks fine.
For an abitrary external function, it's all fine as it should
be, boiling down to a single memcpy in foo() and a direct
memset in main(): https://run.dlang.io/is/O1aeLK
Well somethings wrong if writeln causes optimization to not
occur, if that is the case then it'd be best to just use printf()
instead. Anyways using small examples to show optimization is
usually not what's going to happen in actual code. Functions are
rarely that simple, and if adding a single writeln() to a call is
enough to eliminate that optimization, I can only imagine what
other little things do as well.