digitalmars.D.internals - Better code gen for nothrow functions
- Walter Bright (65/65) Nov 25 2017 https://github.com/dlang/dmd/pull/7361
https://github.com/dlang/dmd/pull/7361 I'm pretty pleased with the results. Consider the code: void bar(); int test() { try { bar(); return 0; } finally { bar(); } } This compiles to: push EBP mov EBP,ESP mov EDX,FS:__except_list push 0FFFFFFFFh push offset _D4test5test2FZi[087h] push EDX mov FS:__except_list,ESP sub ESP,014h mov -020h[EBP],EBX mov -01Ch[EBP],ESI mov -018h[EBP],EDI xor EAX,EAX mov -4[EBP],EAX call near ptr _D4test3barFZv xor EAX,EAX mov dword ptr -4[EBP],0FFFFFFFFh push EAX call near ptr L60 pop EAX mov ECX,-0Ch[EBP] mov FS:__except_list,ECX mov EBX,-020h[EBP] mov ESI,-01Ch[EBP] mov EDI,-018h[EBP] mov ESP,EBP pop EBP ret call near ptr L60 jmp short L6D L60: mov dword ptr -4[EBP],0FFFFFFFFh call near ptr _D4test3barFZv ret L6D: mov ECX,-0Ch[EBP] mov FS:__except_list,ECX mov EBX,-020h[EBP] mov ESI,-01Ch[EBP] mov EDI,-018h[EBP] mov ESP,EBP pop EBP ret mov EAX,offset FLAT:_DATA jmp near ptr __d_framehandler But if nothrow is added to bar(): push EAX call near ptr _D4test3barFNbZv call near ptr _D4test3barFNbZv xor EAX,EAX pop ECX ret Note that it wasn't necessary to add nothrow to test(). The disparity isn't as great on other platforms, but it's still significant. This will make RAII in -betterC much better, and nothrow functions quite worthwhile in general.
Nov 25 2017