[Bug 197] New: Optimize final switch

via D.gnu d.gnu at puremagic.com
Thu Aug 20 02:43:36 PDT 2015


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 at gdcproject.org
          Reporter: johannespfau at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20150820/32fa20bf/attachment.html>


More information about the D.gnu mailing list