[Issue 17083] New: final switch(bool) should be lowered at least to a simple if else

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jan 10 15:37:39 PST 2017


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

          Issue ID: 17083
           Summary: final switch(bool) should be lowered at least to a
                    simple if else
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: performance
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: b2.temp at gmx.com

This function

bool foo(bool b)
{
    final switch(b)
    {
        case true: return b;
        case false: return b;
    }
}

generates, with -O -release, this incredible bloat:

;------- SUB 000000000045E360h -------
000000000045E360h  push rbp
000000000045E361h  mov rbp, rsp
000000000045E364h  sub rsp, 10h
000000000045E368h  mov dword ptr [rbp-08h], edi
000000000045E36Bh  movzx eax, byte ptr [rbp-08h]
000000000045E36Fh  test eax, eax
000000000045E371h  je 0045E37Ah
000000000045E373h  cmp eax, 01h
000000000045E376h  je 0045E37Ah
000000000045E378h  jmp 0045E383h
000000000045E37Ah  movsx eax, byte ptr [rbp-08h]
000000000045E37Eh  mov rsp, rbp
000000000045E381h  pop rbp
000000000045E382h  ret 
000000000045E383h  hlt 
000000000045E384h  nop dword ptr [rax+00h]
000000000045E388h  push rbp
000000000045E389h  mov rbp, rsp
000000000045E38Ch  lea rsi, qword ptr [000000000045E360h]
000000000045E393h  mov edi, 00000001h
000000000045E398h  call 000000000045EB80h
000000000045E39Dh  mov rdi, rax
000000000045E3A0h  mov rsi, rdx
000000000045E3A3h  call 000000000045E3B0h
000000000045E3A8h  xor eax, eax
000000000045E3AAh  pop rbp
000000000045E3ABh  ret 
;------------------------------------
 

while GDC or LDC optimizers seems to handle this more reasonably.
 

--


More information about the Digitalmars-d-bugs mailing list