Bug 9722 – optimizer kills GOT to EBX load

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2013-03-14T13:50:00Z
Last change time
2015-06-09T05:11:53Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2013-03-14T13:50:09Z
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
Comment #1 by bugzilla — 2013-03-14T16:12:56Z
Comment #2 by code — 2013-03-14T20:15:11Z
-------------------- 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 by github-bugzilla — 2013-03-14T20:15:12Z
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
Comment #4 by bugzilla — 2013-03-15T11:01:20Z
Martin, are you saying this bug should still be open?
Comment #5 by code — 2013-03-15T13:48:10Z
(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.
Comment #6 by code — 2013-03-15T14:25:05Z
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.
Comment #7 by github-bugzilla — 2013-03-15T14:40:24Z
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
Comment #8 by code — 2013-03-18T23:58:10Z
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