https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82434
Bug ID: 82434 Summary: -fstore-merging does not work reliably. Product: gcc Version: 7.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: maxim.yegorushkin at gmail dot com Target Milestone: --- Consider the following code: struct A { long a; bool b, c, d, e; }; struct B { long a; bool b, c, d, e; ~B(); }; A f() { A a; a.a = 1; a.b = true; a.c = true; a.d = true; a.e = true; return a; } B g() { B b; b.a = 1; b.b = true; b.c = true; b.d = true; b.e = true; return b; } And the generated assembly: f(): movl $1, %eax movl $16843009, %edx ret g(): movq %rdi, %rax movq $1, (%rdi) movb $1, 8(%rdi) movb $1, 9(%rdi) movb $1, 10(%rdi) movb $1, 11(%rdi) ret Declaring a destructor prevents returning an object of B in registers, which is well documented. Why isn't store merging applied in function g please?