[Bug 147] GDC emits unnecessary dead struct inits

via D.gnu d.gnu at puremagic.com
Thu Jul 31 06:10:50 PDT 2014


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

art.08.09 at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |art.08.09 at gmail.com

--- Comment #2 from art.08.09 at gmail.com ---
I reported this because I was suspecting it was a symptom of some frontend+glue
problem, which was preventing the dead code from being removed. But I've now 
checked what GCC does for similar 'C' cases and apparently the problem exists
there too, it's just not as visible in 'C' because of the lack of default init.
So this might be an upstream issue and could be closed, if you think there
isn't anything that could be done about it in GDC.

Because of the default initialization in D and frequent use of structs for
creating new types, the impact of this missed optimization is much larger than
for C. For example, a bounds-checked int implementation becomes more expensive
because of this.

I tried a few other things, but was not able to find a workaround. Eg

-------------------------------------------------------
void main(string[] argv) {
   S a = void; 

   import gcc.builtins;
   __builtin_memset(&a, 0, S.sizeof);

   a.v = argv.length; /* Modifies the whole struct. */

   if (a.v==42)
      f();
}
-------------------------------------------------------

In this case the memset *is* completely eliminated. But now the unnecessary a.v
store isn't removed...

-- 
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/20140731/49e703c5/attachment.html>


More information about the D.gnu mailing list