[block-freq] Add BlockFrequency::scale that returns a remainder from the division...
authorMichael Gottesman <mgottesman@apple.com>
Sun, 17 Nov 2013 03:25:24 +0000 (03:25 +0000)
committerMichael Gottesman <mgottesman@apple.com>
Sun, 17 Nov 2013 03:25:24 +0000 (03:25 +0000)
commite7a1e3ee8279f12d0f2b49fb198d577949795c88
tree14e5e6af966229b0636a5b96eb1a736b33c18df8
parent8417e857818e972f318bd549caabc54bdf537c26
[block-freq] Add BlockFrequency::scale that returns a remainder from the division and make the private scale in BlockFrequency more performant.

This change is the first in a series of changes improving LLVM's Block
Frequency propogation implementation to not lose probability mass in
branchy code when propogating block frequency information from a basic
block to its successors. This patch is a simple infrastructure
improvement that does not actually modify the block frequency
algorithm. The specific changes are:

1. Changes the division algorithm used when scaling block frequencies by
branch probabilities to a short division algorithm. This gives us the
remainder for free as well as provides a nice speed boost. When I
benched the old routine and the new routine on a Sandy Bridge iMac with
disabled turbo mode performing 8192 iterations on an array of length
32768, I saw ~600% increase in speed in mean/median performance.

2. Exposes a scale method that returns a remainder. This is important so
we can ensure that when we scale a block frequency by some branch
probability BP = N/D, the remainder from the division by D can be
retrieved and propagated to other children to ensure no probability mass
is lost (more to come on this).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194950 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/BlockFrequency.h
lib/Support/BlockFrequency.cpp
unittests/Support/BlockFrequencyTest.cpp