[Bug 147] New: GDC emits unnecessary dead struct inits

via D.gnu d.gnu at puremagic.com
Mon Jul 28 10:20:34 PDT 2014


http://bugzilla.gdcproject.org/show_bug.cgi?id=147

            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 at gdcproject.org
          Reporter: art.08.09 at 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.

-- 
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20140728/46bef9e0/attachment.html>


More information about the D.gnu mailing list