<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - unreachable reduces performance"
   href="https://llvm.org/bugs/show_bug.cgi?id=25952">25952</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>unreachable reduces performance
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>g.bergmann.official@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=15526" name="attach_15526" title="brainfuck interpreter and example data">attachment 15526</a> <a href="attachment.cgi?id=15526&action=edit" title="brainfuck interpreter and example data">[details]</a></span>
brainfuck interpreter and example data

Delaring cases in a switch statement like below as unreachable may reduce
performance:
switch x {
    case 0: // ...
        break;
    case 1: // ...
        break;
 // ....
    case 7: // ...
        break;

    default:
        __builtin_unreachable();
}

Removing the __builtin_unreachable() improves the performance. On my PC the
attached example needs about 25 with it and 17 without.
The attached code is a simple brainfuck interpreter that can be tested by
calling "brainfuck-optimized mandel.brainfuck".
It was test with options -O3 and -O2 as 64 bit build on a haswell processor.
The problem is reproducible in Rust.


Profiling shows a suspiciously high number of branch mispredictions. From what
I have seen of the assembler code, I think that nested conditional branches
like a binary search are faster than a branch table by causing fewer
mispredictions.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>