]> granicus.if.org Git - llvm/commit
[CGP] Split some critical edges coming out of indirect branches
authorMichael Kuperstein <mkuper@google.com>
Fri, 24 Feb 2017 18:41:32 +0000 (18:41 +0000)
committerMichael Kuperstein <mkuper@google.com>
Fri, 24 Feb 2017 18:41:32 +0000 (18:41 +0000)
commit98ee128c8e35a9f372dfc45dcdb00afd38b3fe3b
treeb192247d79226d02fffc1be4cec0c4cfabc83e28
parent0ab7c7b1f01b3b401a98cf17037f1cd70027a1e2
[CGP] Split some critical edges coming out of indirect branches

Splitting critical edges when one of the source edges is an indirectbr
is hard in general (because it requires changing the memory the indirectbr
reads). But if a block only has a single indirectbr predecessor (which is
the common case), we can simulate splitting that edge by splitting
the destination block, and retargeting the *direct* branches.

This is motivated by the use of computed gotos in python 2.7: PyEval_EvalFrame()
ends up using an indirect branch with ~100 successors, and passing a constant to
each of those. Since MachineSink can't break indirect critical edges on demand
(and doing this in MIR doesn't look feasible), this causes us to emit about ~100
defs of registers containing constants, which we in the predecessor block, where
only one of those constants is used in each successor. So, at each computed goto,
we needlessly spill about a 100 constants to stack. The end result is that a
clang-compiled python interpreter can be about ~2.5x slower on a simple python
reduction loop than a gcc-compiled interpreter.

Differential Revision: https://reviews.llvm.org/D29916

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296149 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CodeGenPrepare.cpp
test/CodeGen/ARM/indirectbr.ll
test/CodeGen/MSP430/indirectbr2.ll
test/CodeGen/PowerPC/indirectbr.ll
test/Transforms/CodeGenPrepare/X86/computedgoto.ll [new file with mode: 0644]