www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Bug 197] New: Optimize final switch

Date: Thu, 20 Aug 2015 10:43:36 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"

http://bugzilla.gdcproject.org/show_bug.cgi?id=197

            Bug ID: 197
           Summary: Optimize final switch
           Product: GDC
           Version: development
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: Normal
         Component: gdc
          Assignee: ibuclaw gdcproject.org
          Reporter: johannespfau gmail.com

D example:
---------------------------------------------------------
enum TestEnum
{
    a,
    b,
    c,
    d,
    e
}

int foo(TestEnum e)
{
    final switch(e)
    {
        case TestEnum.a:
            return 10;
        case TestEnum.b:
            return 11;
        case TestEnum.c:
            return 12;
        case TestEnum.d:
            return 13;
        case TestEnum.e:
            return 14;
    }
}
---------------------------------------------------------

Generates:
---------------------------------------------------------
    cmpl    $4, -4(%rbp)
    ja  .L2
    ; [jump table]
.L2:
    popq    %rbp
---------------------------------------------------------

For a normal switch, the cmpl is used to check if the enum value is not handled
in the switch case, so the jump table can't be used (no index in the table for
that value). For a final switch (in release mode) this can't happen and we
could remove the check.

However, the gcc backend doesn't support optimizing this case:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49054

GDC- implementation (useless without backend support):
https://github.com/D-Programming-GDC/GDC/pull/135

-- 
You are receiving this mail because:
You are watching all bug changes.
Aug 20 2015