<html>
    <head>
      <base href="http://bugzilla.gdcproject.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Optimize final switch"
   href="http://bugzilla.gdcproject.org/show_bug.cgi?id=197">197</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Optimize final switch
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>GDC
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>development
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>gdc
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>ibuclaw@gdcproject.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>johannespfau@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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:
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49054">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49054</a>

GDC- implementation (useless without backend support):
<a href="https://github.com/D-Programming-GDC/GDC/pull/135">https://github.com/D-Programming-GDC/GDC/pull/135</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are watching all bug changes.</li>
      </ul>
    </body>
</html>