Thread overview
[Issue 9722] New: optimizer kills GOT to EBX load
Mar 14, 2013
Martin Nowak
Mar 14, 2013
Walter Bright
Mar 15, 2013
Martin Nowak
Mar 15, 2013
Martin Nowak
Mar 15, 2013
Martin Nowak
Mar 15, 2013
Walter Bright
Mar 15, 2013
Martin Nowak
Mar 15, 2013
Martin Nowak
Mar 19, 2013
Martin Nowak
March 14, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722

           Summary: optimizer kills GOT to EBX load
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: code@dawg.eu


--- Comment #0 from Martin Nowak <code@dawg.eu> 2013-03-14 13:50:09 PDT ---
cat > bug.d << CODE
void foo()
{
    bar();
}

void bar()
{
}
CODE

--------------------
dmd -c -fPIC -m32 bug
--------------------
_D3bug3fooFZv PROC NEAR
        push    ebp                                     ; 0000 _ 55
        mov     ebp, esp                                ; 0001 _ 8B. EC
        sub     esp, 4                                  ; 0003 _ 83. EC, 04
        push    ebx                                     ; 0006 _ 53
        call    ?_003                                   ; 0007 _ E8, 00000000

?_003   LABEL NEAR
        pop     eax                                     ; 000C _ 58
        add     eax, offset _GLOBAL_OFFSET_TABLE_-$+1H  ; 000D _ 05,
00000002(GOT r)
        mov     dword ptr [ebp-4H], eax                 ; 0012 _ 89. 45, FC
        mov     ebx, dword ptr [ebp-4H]                 ; 0015 _ 8B. 5D, FC
        call    _D3bug3barFZv                           ; 0018 _ E8,
FFFFFFFC(PLT r)
        pop     ebx                                     ; 001D _ 5B
        leave                                           ; 001E _ C9
        ret                                             ; 001F _ C3
_D3bug3fooFZv ENDP
--------------------
dmd -c -fPIC -m32 -O bug
--------------------
_D3bug3fooFZv PROC NEAR
        push    ebp                                     ; 0000 _ 55
        mov     ebp, esp                                ; 0001 _ 8B. EC
        push    eax                                     ; 0003 _ 50
        push    ebx                                     ; 0004 _ 53
        call    _D3bug3barFZv                           ; 0005 _ E8,
FFFFFFFC(PLT r)
        pop     ebx                                     ; 000A _ 5B
        mov     esp, ebp                                ; 000B _ 8B. E5
        pop     ebp                                     ; 000D _ 5D
        ret                                             ; 000E _ C3
_D3bug3fooFZv ENDP

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 14, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2013-03-14 16:12:56 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1748

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722



--- Comment #2 from Martin Nowak <code@dawg.eu> 2013-03-14 20:15:11 PDT ---
--------------------
dmd -c -fPIC -m32 -O bug
--------------------
_D3bug3fooFZv PROC NEAR
        push    ebp                                     ; 0000 _ 55
        mov     ebp, esp                                ; 0001 _ 8B. EC
        push    eax                                     ; 0003 _ 50
        push    ebx                                     ; 0004 _ 53
        call    ?_003                                   ; 0005 _ E8, 00000000

?_003   LABEL NEAR
        pop     ebx                                     ; 000A _ 5B
        add     ebx, offset _GLOBAL_OFFSET_TABLE_-$+1H  ; 000B _ 81. C3,
00000003(GOT r)
        call    _D3bug3barFZv                           ; 0011 _ E8,
FFFFFFFC(PLT r)
        pop     ebx                                     ; 0016 _ 5B
        mov     esp, ebp                                ; 0017 _ 8B. E5
        pop     ebp                                     ; 0019 _ 5D
        ret                                             ; 001A _ C3
_D3bug3fooFZv ENDP

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722



--- Comment #2 from Martin Nowak <code@dawg.eu> 2013-03-14 20:15:11 PDT ---
--------------------
dmd -c -fPIC -m32 -O bug
--------------------
_D3bug3fooFZv PROC NEAR
        push    ebp                                     ; 0000 _ 55
        mov     ebp, esp                                ; 0001 _ 8B. EC
        push    eax                                     ; 0003 _ 50
        push    ebx                                     ; 0004 _ 53
        call    ?_003                                   ; 0005 _ E8, 00000000

?_003   LABEL NEAR
        pop     ebx                                     ; 000A _ 5B
        add     ebx, offset _GLOBAL_OFFSET_TABLE_-$+1H  ; 000B _ 81. C3,
00000003(GOT r)
        call    _D3bug3barFZv                           ; 0011 _ E8,
FFFFFFFC(PLT r)
        pop     ebx                                     ; 0016 _ 5B
        mov     esp, ebp                                ; 0017 _ 8B. E5
        pop     ebp                                     ; 0019 _ 5D
        ret                                             ; 001A _ C3
_D3bug3fooFZv ENDP

--- Comment #3 from github-bugzilla@puremagic.com 2013-03-14 20:15:12 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c3fa2edf6a1881f59afdcf101ba0f4a592f62c67 fix Issue 9722 - optimizer kills GOT to EBX load

https://github.com/D-Programming-Language/dmd/commit/28b16887c2007838e7bae7aff6e26aec5466398b Merge pull request #1748 from WalterBright/fix9722

fix Issue 9722 - optimizer kills GOT to EBX load

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722



--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2013-03-15 11:01:20 PDT ---
Martin, are you saying this bug should still be open?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722



--- Comment #5 from Martin Nowak <code@dawg.eu> 2013-03-15 13:48:10 PDT ---
(In reply to comment #4)
> Martin, are you saying this bug should still be open?

No, the bug is fixed but it's terribly inefficient when the GOT isn't cached. What happens now is that the optimizer kills the unreferenced localgot variable and instead the GOT address is loaded anew for every access.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


--- Comment #6 from Martin Nowak <code@dawg.eu> 2013-03-15 14:25:05 PDT ---
A slightly different case of the bug that still happens.
I haven't had time to reduce it yet though.

--------------------
dmd -c -m32 -fPIC -O druntime/src/core/runtime.d
--------------------
runModuleUnitTests PROC NEAR
        push    ebp                                     ; 0000 _ 55
        mov     ebp, esp                                ; 0001 _ 8B. EC
        sub     esp, 436                                ; 0003 _ 81. EC,
000001B4
        push    ebx                                     ; 0009 _ 53
        mov     ecx, 35                                 ; 000A _ B9, 00000023
        xor     eax, eax                                ; 000F _ 31. C0
        push    esi                                     ; 0011 _ 56
        push    edi                                     ; 0012 _ 57
        lea     edi, [ebp-1B4H]                         ; 0013 _ 8D. BD,
FFFFFE4C
        rep stosd                                       ; 0019 _ F3: AB
        lea     ecx, [ebp-1B0H]                         ; 001B _ 8D. 8D,
FFFFFE50
        push    ecx                                     ; 0021 _ 51
        mov     ebx, dword ptr [ebp-4H]                 ; 0022 _ 8B. 5D, FC
        call    sigfillset                              ; 0025 _ E8,
FFFFFFFC(PLT r)
...

The instruction that loads the GOT address from the stack is there but the part that stores it on the stack has been optimized away.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722



--- Comment #7 from github-bugzilla@puremagic.com 2013-03-15 14:40:24 PDT ---
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/1ab4ee51bcb6821c368c58fc9ac9672f69b12340 Merge pull request #1748 from WalterBright/fix9722

fix Issue 9722 - optimizer kills GOT to EBX load

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9722


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #8 from Martin Nowak <code@dawg.eu> 2013-03-18 23:58:10 PDT ---
Fixed

https://github.com/D-Programming-Language/dmd/commit/578caf27faf03383efadfac19596706714278d7a Improve code gen for localgot

https://github.com/D-Programming-Language/dmd/commit/31f32c71a56ad671bc870761cf6a41a587108ba8 Merge pull request #1752 from WalterBright/improvelocalgot

Improve code gen for localgot

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