[SimplifyCFG] Speculatively flatten CFG based on profiling metadata
authorPhilip Reames <listmail@philipreames.com>
Wed, 14 Oct 2015 22:46:19 +0000 (22:46 +0000)
committerPhilip Reames <listmail@philipreames.com>
Wed, 14 Oct 2015 22:46:19 +0000 (22:46 +0000)
commitf642f48961a86754fdea9e66f066929d4b0f44bf
tree3e441b82721f97522485698dbad50e4a7091b11e
parent07c629ffc074853c4fb3c01ae3c81b84199be070
[SimplifyCFG] Speculatively flatten CFG based on profiling metadata

If we have a series of branches which are all unlikely to fail, we can possibly combine them into a single check on the fastpath combined with a bit of dispatch logic on the slowpath. We don't want to do this unconditionally since it requires speculating instructions past a branch, but if the profiling metadata on the branch indicates profitability, this can reduce the number of checks needed along the fast path.

The canonical example this is trying to handle is removing the second bounds check implied by the Java code: a[i] + a[i+1]. Note that it can currently only do so for really simple conditions and the values of a[i] can't be used anywhere except in the addition. (i.e. the load has to have been sunk already and not prevent speculation.) I plan on extending this transform over the next few days to handle alternate sequences.

Differential Revision: http://reviews.llvm.org/D13070

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250343 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/SimplifyCFG.cpp