[llvm-bugs] [Bug 25952] New: unreachable reduces performance

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 27 15:39:51 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25952

            Bug ID: 25952
           Summary: unreachable reduces performance
           Product: new-bugs
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: g.bergmann.official at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 15526
  --> https://llvm.org/bugs/attachment.cgi?id=15526&action=edit
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151227/5033c57a/attachment.html>


More information about the llvm-bugs mailing list