Jump to page: 1 2 3
Thread overview
[Issue 2356] New: array literal as non static initializer generates horribly inefficient code.
Sep 11, 2008
d-bugmail
Sep 15, 2008
d-bugmail
Apr 08, 2009
d-bugmail
Sep 09, 2011
Kenji Hara
Sep 09, 2011
Kenji Hara
Oct 08, 2011
dawg@dawgfoto.de
Feb 02, 2012
yebblies
Feb 02, 2012
yebblies
Feb 02, 2012
yebblies
May 05, 2012
Kenji Hara
Oct 14, 2012
Jonathan M Davis
Oct 28, 2012
yebblies
Oct 30, 2012
Denis Shelomovskij
Apr 10, 2013
Kenji Hara
Apr 11, 2013
Kenji Hara
Jun 06, 2013
Benjamin Thaut
Oct 24, 2013
Denis Shelomovskij
Oct 24, 2013
Denis Shelomovskij
September 11, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2356

           Summary: array literal as non static initializer generates
                    horribly inefficient code.
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: tomas@famolsen.dk


this simple test:

void main()
{
    int[3] x = [1,2,3];
}

should just initialize x with the values 1,2,3

what happens in reality is not as nice as this output of obj2asm shows:

_Dmain:
                push    EBP
                mov     EBP,ESP
                sub     ESP,0Ch
                push    EBX
                lea     EAX,-0Ch[EBP]
                push    EAX
                push    3
                push    3
                push    2
                push    1
                push    3
                mov     ECX,offset FLAT:_D11TypeInfo_Ai6__initZ@SYM32
                push    ECX
                call    near ptr _d_arrayliteralT@PC32
                add     ESP,014h
                mov     EDX,EAX
                mov     EBX,3
                push    EDX
                push    EBX
                push    4
                call    near ptr _d_arraycopy@PC32
                xor     EAX,EAX
                add     ESP,014h
                pop     EBX
                leave
                ret


I'm marking it wrong-code, even though the code does compile and link, it's just wrong ... I'm using 1.034 but I'd guess it's an older bug, so I'm not marking a specific version.


-- 

September 15, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2356


tomas@famolsen.dk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |1.034




------- Comment #1 from tomas@famolsen.dk  2008-09-15 08:52 -------
I think this issue might have been introduced in DMD 1.034, as I've hit several issues in LLVMDC, that used to work, due to some initializers suddenly being ArrayLiterals instead of ArrayInitializers. Marking version 1.034.


-- 

April 08, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2356


clugdbug@yahoo.com.au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |performance




------- Comment #2 from clugdbug@yahoo.com.au  2009-04-08 08:01 -------
This is a performance issue, not wrong-code.


-- 

July 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2356


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from bearophile_hugs@eml.cc 2010-07-19 23:18:32 PDT ---
*** Issue 4488 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2356


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2011-09-09 09:35:07 PDT ---
https://github.com/D-Programming-Language/dmd/pull/375

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2356



--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2011-09-09 09:36:49 PDT ---
After applying my patch, the sample code generates like follows:
(output of ddbg in 64-bit Windows 7)

c:\d\test.d:1 void main()
00402010: c80c0000                enter 0xc, 0x0
c:\d\test.d:3     int[3] x = [1,2,3];
00402014: c745f401000000          mov dword [ebp-0xc], 0x1
0040201b: c745f802000000          mov dword [ebp-0x8], 0x2
00402022: c745fc03000000          mov dword [ebp-0x4], 0x3
00402029: 31c0                    xor eax, eax
test.obj
0040202b: c9                      leave
0040202c: c3                      ret

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 08, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2356


dawg@dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dawg@dawgfoto.de


--- Comment #6 from dawg@dawgfoto.de 2011-10-07 19:09:44 PDT ---
This is also a huge issue when assigning .init to a static array.

ubyte[1024] v;
v = typeof(v).init;

This will generate a dynamically allocated [0, 0, 0 ... ] Arrayliteral for the rhs expression before calling _d_arraycopy. Even worse the allocated ArrayLiteral is initialized using 1024 comma expressions. Using -O the compiler will subsequently almost starve from O(N^2) behavior during comsub eliminations.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2356


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rsinfu@gmail.com


--- Comment #7 from yebblies <yebblies@gmail.com> 2012-02-02 14:27:49 EST ---
*** Issue 4298 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2356


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sean@invisibleduck.org


--- Comment #8 from yebblies <yebblies@gmail.com> 2012-02-02 15:34:11 EST ---
*** Issue 4881 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2356


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jarrett.billingsley@gmail.c
                   |                            |om


--- Comment #9 from yebblies <yebblies@gmail.com> 2012-02-02 20:49:34 EST ---
*** Issue 2237 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2 3