Bug 20990 – Optimizer should move cold branches to the end of the function

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-28T20:45:22Z
Last change time
2020-07-06T21:38:53Z
Keywords
performance, pull
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2020-06-28T20:45:22Z
assert is a cold branch, and DMD move the assert to the end for the example: void test(int* ptr) { if (ptr is null) assert(false); *ptr = 42; } But it does do it for: void test(int* ptr) { assert(ptr); *ptr = 42; } assume CS:__D4testQfFPiZv L0: push EAX test EAX,EAX push EAX je L10 mov dword ptr [EAX],02Ah add ESP,8 ret L10: mov dword ptr 4[ESP],4 mov [ESP],offset FLAT:___a6_746573742e64 call near ptr __d_assertp It should also do it for the former.
Comment #1 by bugzilla — 2020-06-28T20:47:30Z
(In reply to Walter Bright from comment #0) > assert is a cold branch, and DMD move the assert to the end for the example: I meant it does "not move" the assert.
Comment #2 by ibuclaw — 2020-06-28T21:59:25Z
(In reply to Walter Bright from comment #1) > (In reply to Walter Bright from comment #0) > > assert is a cold branch, and DMD move the assert to the end for the example: > > I meant it does "not move" the assert. Everything that follows the assert should also be considered cold too. Though hopefully "unreachable" warnings/errors would occur before that point.
Comment #3 by bugzilla — 2020-06-30T09:02:30Z
(In reply to Iain Buclaw from comment #2) > Everything that follows the assert should also be considered cold too. Actually, it is not just cold, it is dead and doesn't make it to the executable. > Though hopefully "unreachable" warnings/errors would occur before that point. It does if warnings are enabled (-w switch).
Comment #4 by dlang-bot — 2020-07-05T04:44:54Z
@WalterBright created dlang/dmd pull request #11374 "fix Issue 20990 - Optimizer should move cold branches to the end of t…" fixing this issue: - fix Issue 20990 - Optimizer should move cold branches to the end of the function https://github.com/dlang/dmd/pull/11374
Comment #5 by dlang-bot — 2020-07-06T21:38:53Z
dlang/dmd pull request #11374 "fix Issue 20990 - Optimizer should move cold branches to the end of t…" was merged into master: - f1b5b1d676b4385b7790bbb0d4a316dd3cc2f92e by Walter Bright: fix Issue 20990 - Optimizer should move cold branches to the end of the function https://github.com/dlang/dmd/pull/11374