Bug ID | 147 |
---|---|
Summary | GDC emits unnecessary dead struct inits |
Product | GDC |
Version | 4.9.x |
Hardware | All |
OS | All |
Status | NEW |
Severity | normal |
Priority | Normal |
Component | gdc |
Assignee | ibuclaw@gdcproject.org |
Reporter | art.08.09@gmail.com |
-------------------------------------------------------- void f() { assert(0); } struct S { ulong v; } void main(string[] argv) { S a; /* Adding `= void` here results in sane codegen, but shouldn't be necessary. */ a.v = argv.length; /* Modifies the whole struct. */ if (a.v==42) f(); } --------------------------------------------------------- using current gcc4.9 based git head, gdc -m64 -O3: 0000000000402970 <void bugzdeadstore1.f()>: 402970: 48 83 ec 08 sub $0x8,%rsp 402974: ba 04 00 00 00 mov $0x4,%edx 402979: bf 10 00 00 00 mov $0x10,%edi 40297e: be 84 1f 44 00 mov $0x441f84,%esi 402983: e8 28 e6 00 00 callq 410fb0 <_d_assert> 0000000000402990 <_Dmain>: 402990: 48 83 ec 18 sub $0x18,%rsp 402994: 48 83 ff 2a cmp $0x2a,%rdi 402998: 48 c7 04 24 00 00 00 movq $0x0,(%rsp) 40299f: 00 4029a0: 74 07 je 4029a9 <_Dmain+0x19> 4029a2: 31 c0 xor %eax,%eax 4029a4: 48 83 c4 18 add $0x18,%rsp 4029a8: c3 retq 4029a9: e8 c2 ff ff ff callq 402970 <void bugzdeadstore1.f()> That dead store @402998 is unnecessary. It disappears when `a` is initted to `void`, but that is not a practical (nor safe) solution for real code (this is obviously a very reduced example). There are other issues with non-POD object related codegen (especially for @noinline functions), but this one is bad because it affects PODs and makes even simple type wrapping expensive.