www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20990] New: Optimizer should move cold branches to the end of

https://issues.dlang.org/show_bug.cgi?id=20990

          Issue ID: 20990
           Summary: Optimizer should move cold branches to the end of the
                    function
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

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.

--
Jun 28 2020