[Bug c++/57971] Improve copy elision when returning structs by value

2024-03-17 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57971

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2024-03-17

--- Comment #2 from Andrew Pinski  ---
Confirmed. clang is able to optimize this case.

[Bug c++/57971] Improve copy elision when returning structs by value

2015-01-10 Thread gcc-bugzilla at contacts dot eelis.net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57971

Eelis gcc-bugzilla at contacts dot eelis.net changed:

   What|Removed |Added

 CC||gcc-bugzilla at contacts dot 
eelis
   ||.net

--- Comment #1 from Eelis gcc-bugzilla at contacts dot eelis.net ---
struct foo { foo(); foo(foo const ); };

foo bar();

foo fast(bool b) {
if (b) return foo();
return bar();
}

/* produces (with -O3):

_Z4fastb:
.LFB0:
testb%sil, %sil
pushq%rbx
movq%rdi, %rbx
jne.L6
call_Z3barv
movq%rbx, %rax
popq%rbx
ret
.p2align 4,,10
.p2align 3
.L6:
call_ZN3fooC1Ev
movq%rbx, %rax
popq%rbx
ret
*/

foo slow(bool b) {
if (b) return foo();
foo f = bar();
return f;
}

/* produces (with -O3):

_Z4slowb:
.LFB1:
pushq%rbx
movq%rdi, %rbx
subq$16, %rsp
testb%sil, %sil
jne.L11
leaq15(%rsp), %rdi
call_Z3barv
leaq15(%rsp), %rsi
movq%rbx, %rdi
call_ZN3fooC1ERKS_
addq$16, %rsp
movq%rbx, %rax
popq%rbx
ret
.p2align 4,,10
.p2align 3
.L11:
call_ZN3fooC1Ev
addq$16, %rsp
movq%rbx, %rax
popq%rbx
ret
*/