<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/106846>106846</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            performance regression in clang-19 when using computed goto
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mikulas-patocka
      </td>
    </tr>
</table>

<pre>
    Hi

I noticed that the Ajla programming language ( https://www.ajla-lang.cz/ ) runs slower when being compiled by clang-19 compared to clang-18 or gcc-14. I looked at the assembler, and it turns out that the bytecode interpreter (the file "ipret.c") is not compiled as efficiently as it could be. In particular, clang-19 joins all the "goto *next_label" statements in a function into just one "jmp *" instruction. That reduces code size, but it also makes branch prediction inefficient, because the CPU cannot learn that a single instruction jumps to multiple targets.

I created this example that shows the issue:
http://www.jikos.cz/~mikulas/testcases/clang/computed-goto.c
(use: clang-19 -O2 computed-goto.c && time ./a.out)

The results (in seconds) are here:
http://www.jikos.cz/~mikulas/testcases/clang/computed-goto.txt

We can see that the worst slowdown happens on Sandy Bridge. Zen 4 shows no slowdown, so it seems that it has smart indirect branch predictor that can predict multiple jump targets from a single instruction.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0lM-O4zYMxp9GuRAxYuXPJAcfZncRdE8t0C0K9FLQMmMrI0uGSG1m9tBnL-hkJjOLXnuJY1mkvo_8icjs-0jUmO0ns_2ywCJDys3on0pAXk4oyT3hok3dS_OLN6svZvV4_f0KMYl31IEMKCADweM5IEw59RnH0cceAsa-YE9g7B4GkYnN-tHYo7HHy-VS4TngUvdU7oexRzD2ALlEBg7pQhkuA0VoSTO5NE4-UAftCzgNWdaHeRGzKkivi3tIGXrnlvWmgq8QUnqiDm76kJnGNlA29jNg7MALSMmRIRW522hfhFzqCHwUylMmoawO9NvJB3VjvS5Xzliroj1rMe4ikYFOJ-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