[PATCH] D33577: CodeGen: BlockPlacement: Use Branching factor to choose between near equals.

Kyle Butt via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 25 16:36:09 PDT 2017


iteratee created this revision.
Herald added subscribers: jgravelle-google, sbc100, javed.absar, nemanjai, dschuff, jfb.

When choosing between blocks of approximately the same probability, we need some
other metric to choose between them. In this patch, we add the simple metric of
"Branch Factor", which is the number of independent blocks that can be reached
from a block without crossing a join point (A block with multiple successors).
This is related to the classical "Branch Factor" similarly to how a 2-3-4 tree
is related to a red-black tree. These nodes could in theory all be rolled up
into a single node like a switch. If we did that, the calculated value would be
the branching factor of that single node.

Another way of viewing this is if you don't cross join-points, you're
essentially finding a sub-tree in the CFG. We're counting the # of leaves in
that subtree.

The motivation here is that when choosing between a list of alternatives like
this:

if (v < (1<<7)) {
...
} else if (v < (1<<14)) {
...
} else if (v < (1<<21)) {
...
} else if (v < (1<<28)) {
...
} else {
...
}

That we should prefer to fall through to the next test, because those tests have
a larger number of branches they have to pass through in order to be executed.
Even if our estimates of 50% probabilities are correct for these branches,
Having the fallthrough go to the next test helps to reduce tail latency because
it reduces the # of taken branches to get to the bottom of the sub-tree of the
CFG. In the above example, each case ends up with 1 taken branch, instead of the
last case requiring 4 taken branches.

Future work: Apply this heuristic or something similar at probability formation,
instead of just in block placement.


Repository:
  rL LLVM

https://reviews.llvm.org/D33577

Files:
  lib/CodeGen/MachineBlockPlacement.cpp
  test/CodeGen/AArch64/combine-comparisons-by-cse.ll
  test/CodeGen/AArch64/machine_cse.ll
  test/CodeGen/ARM/2013-05-05-IfConvertBug.ll
  test/CodeGen/ARM/tail-opts.ll
  test/CodeGen/PowerPC/tail-dup-branch-to-fallthrough.ll
  test/CodeGen/WebAssembly/cfg-stackify.ll
  test/CodeGen/X86/block-placement-branch-factor.mir
  test/CodeGen/X86/block-placement.ll
  test/CodeGen/X86/loop-blocks.ll
  test/CodeGen/X86/tail-merge-after-mbp.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33577.100330.patch
Type: text/x-patch
Size: 25698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170525/bcc2a7ab/attachment.bin>


More information about the llvm-commits mailing list