[llvm] [TailDuplicator] Add a limit on the number of indirect branch successors (PR #78582)

Quentin Dian via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 03:26:28 PST 2024


DianQK wrote:

> The general pattern that's supposed to be targeted by TailDupIndirectBranchSize is something like an interpreter loop. The program executes one interpreter opcode, then jumps to the next opcode. Interpreters tend to have sequences of opcodes where, given an opcode, the next opcode is somewhat predictable. If we merge all the indirect branches of every opcode together, the indirect branch predictor loses the information about the previous opcode. So we want to be a bit more generous in this case. At least, that was the goal when this heuristic was originally added back in 2009. Indirect branch predictors today are probably smarter.

If I understand what you are describing correctly. This duplication is an improvement regardless of the number of predecessors and successors. But I do want to add some limits for the overhead of compile time and code size. As it stands, I think past transformation scenarios that reach 128 predecessors are almost non-existent, otherwise we would have caught the problem earlier? Currently, it's because we removed the default branch exposing this transformation opportunity. Can we at least add a condition to limit this transformation? I think it makes sense to limit the number of predecessors when we encounter indirect branches.

https://github.com/llvm/llvm-project/pull/78582


More information about the llvm-commits mailing list