[Issue 10932] New: Useless temporaries and other absurd in inlined code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 30 13:55:05 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10932

           Summary: Useless temporaries and other absurd in inlined code
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dmitry.olsh at gmail.com


--- Comment #0 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2013-08-30 13:55:02 PDT ---
This is drilling down on the issue of why multi-stage lookup tables of new
std.uni ahve decent speed in LDC and painstakingly slow in DMD.

Observe that the following snippet (inlined opIndex of a Trie) does 2
remarkably stupid things:
a) See that read/write of arg_0 on stack, instead of direct "mov edx, ebx"
b) 2 push eax at the begining of function ... and "add esp, 8" at end - WAT?
Note that eax is never written to until the very end (there is simply no need
to save it).

public
_D3std3uni146__T4TrieTS3std3uni19__T9BitPackedTbVi1Z9BitPackedTwVk1114112TS3std3uni21__T9sliceBi39F8D5E3EE00191D27B7780CD5A2FFED
_D3std3uni146__T4TrieTS3std3uni19__T9BitPackedTbVi1Z9BitPackedTwVk1114112TS3std3uni21__T9sliceBi39F8D5E3EE00191D27B7780CD5A2FFED
proc near
                                     ; CODE XREF:
_D9trie_test4mainFAAyaZv17__foreachbody6846MFNfKwZi+Ap

var_8           = dword ptr -8
arg_0           = dword ptr  4

             push    eax
             mov     ecx, [esp+4+arg_0]
             shr     ecx, 8
             push    eax
             and     ecx, 1FFFh
             mov     edx, [eax+14h]
             push    ebx
             mov     bx, [edx+ecx*2]
             push    esi
             mov     esi, [esp+10h+arg_0]
             and     esi, 0FFh
             push    edi
             mov     edi, [eax+4]
             lea     ecx, [edx+edi*4]
             and     ebx, 0FFFFh
             shl     ebx, 8
             add     ebx, esi
             mov     [esp+14h+var_8], ebx
             mov     edx, [esp+14h+var_8]
             shr     ebx, 5
             and     edx, 1Fh
             bt      [ecx+ebx*4], edx
             sbb     eax, eax
             neg     eax
             pop     edi
             pop     esi
             pop     ebx
             add     esp, 8
             retn    4
_D3std3uni146__T4TrieTS3std3uni19__T9BitPackedTbVi1Z9BitPackedTwVk1114112TS3std3uni21__T9sliceBi39F8D5E3EE00191D27B7780CD5A2FFED
endp


And the D code where the above object code can be seen:
//Command line: dmd -O -release -inline -noboundscheck

import std.uni, std.stdio;

//match bits that std.regex had before
alias codepointSetTrie!(13, 8) makeTrie;

void main(string argv[])
{
    auto tr = makeTrie(unicode.Alphabetic);
    int count;
    foreach(arg; argv)
    foreach(dchar ch; arg)
        if(tr[ch])
            count++;
    writeln(count);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list