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: unassignedb...@nondot.org
          Reporter: g.bergmann.offic...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to