diff options
author | Daniel Jasper <djasper@google.com> | 2015-03-20 10:00:37 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-03-20 10:00:37 +0000 |
commit | 214997c63bc170b7859dcd03c551d6feaacb2dc2 (patch) | |
tree | 3bbbb82211483b89f46967b5a67f433c0cc3a13f /llvm/lib/CodeGen/MachineBlockPlacement.cpp | |
parent | 8ac06996bf6e602888692df1836eeec02966db16 (diff) | |
download | llvm-214997c63bc170b7859dcd03c551d6feaacb2dc2.zip llvm-214997c63bc170b7859dcd03c551d6feaacb2dc2.tar.gz llvm-214997c63bc170b7859dcd03c551d6feaacb2dc2.tar.bz2 |
[MBP] Don't outline short optional branches
With the option -outline-optional-branches, LLVM will place optional
branches out of line (more details on r231230).
With this patch, this is not done for short optional branches. A short
optional branch is a branch containing a single block with an
instruction count below a certain threshold (defaulting to 3). Still
everything is guarded under -outline-optional-branches).
Outlining a short branch can't significantly improve code locality. It
can however decrease performance because of the additional jmp and in
cases where the optional branch is hot. This fixes a compile time
regression I have observed in a benchmark.
Review: http://reviews.llvm.org/D8108
llvm-svn: 232802
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockPlacement.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index 06cc7ba..86a4922 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -74,6 +74,12 @@ static cl::opt<bool> OutlineOptionalBranches( "post dominator, out of line."), cl::init(false), cl::Hidden); +static cl::opt<unsigned> OutlineOptionalThreshold( + "outline-optional-threshold", + cl::desc("Don't outline optional branches that are a single block with an " + "instruction count below this threshold"), + cl::init(4), cl::Hidden); + namespace { class BlockChain; /// \brief Type for our function-wide basic block -> block chain mapping. @@ -377,8 +383,25 @@ MachineBlockPlacement::selectBestSuccessor(MachineBasicBlock *BB, // dominates all terminators of the MachineFunction. If it does, other // successors must be optional. Don't do this for cold branches. if (OutlineOptionalBranches && SuccProb > HotProb.getCompl() && - UnavoidableBlocks.count(Succ) > 0) - return Succ; + UnavoidableBlocks.count(Succ) > 0) { + auto HasShortOptionalBranch = [&]() { + for (MachineBasicBlock *Pred : Succ->predecessors()) { + // Check whether there is an unplaced optional branch. + if (Pred == Succ || (BlockFilter && !BlockFilter->count(Pred)) || + BlockToChain[Pred] == &Chain) + continue; + // Check whether the optional branch has exactly one BB. + if (Pred->pred_size() > 1 || *Pred->pred_begin() != BB) + continue; + // Check whether the optional branch is small. + if (Pred->size() < OutlineOptionalThreshold) + return true; + } + return false; + }; + if (!HasShortOptionalBranch()) + return Succ; + } // Only consider successors which are either "hot", or wouldn't violate // any CFG constraints. |