rvalues -> ref (yup... again!)

kinke noone at nowhere.com
Wed Mar 28 00:11:28 UTC 2018


On Tuesday, 27 March 2018 at 23:35:44 UTC, kinke wrote:
> On Tuesday, 27 March 2018 at 21:52:25 UTC, Rubn wrote:
>> It happens with LDC too, not sure how it would be able to know 
>> to do any kind of optimization like that unless it was able to 
>> inline every single function called into one function and be 
>> able to do optimize it from there. I don't imagine that'll be 
>> likely though.
>
> It does it in your code sample with `-O`, there's no call to 
> bar and the foo() by-value arg is memcpy'd to the global.

For reference: https://run.dlang.io/is/2vDEXP
Note that main() boils down to a `memset(&gfoo, 10, 1024); return 
0;`:

_Dmain:
	.cfi_startproc
	pushq	%rax
.Lcfi0:
	.cfi_def_cfa_offset 16
	data16
	leaq	onlineapp.Foo onlineapp.gfoo at TLSGD(%rip), %rdi
	data16
	data16
	rex64
	callq	__tls_get_addr at PLT
	movl	$10, %esi
	movl	$1024, %edx
	movq	%rax, %rdi
	callq	memset at PLT
	xorl	%eax, %eax
	popq	%rcx
	retq


More information about the Digitalmars-d mailing list