[llvm] r184584 - BlockFrequency: Saturate at 1 instead of 0 when multiplying a frequency with a branch probability.
Benjamin Kramer
benny.kra at gmail.com
Fri Jun 21 12:58:49 PDT 2013
On 21.06.2013, at 21:54, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
>
> On Jun 21, 2013, at 12:30 PM, Benjamin Kramer <benny.kra at googlemail.com> wrote:
>
>> Author: d0k
>> Date: Fri Jun 21 14:30:05 2013
>> New Revision: 184584
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=184584&view=rev
>> Log:
>> BlockFrequency: Saturate at 1 instead of 0 when multiplying a frequency with a branch probability.
>>
>> Zero is used by BlockFrequencyInfo as a special "don't know" value. It also
>> causes a sink for frequencies as you can't ever get off a zero frequency with
>> more multiplies.
>>
>> This recovers a 10% regression on MultiSource/Benchmarks/7zip. A zero frequency
>> was propagated into an inner loop causing excessive spilling.
>>
>> PR16402.
>
> Thanks, Ben
>
>> uint32_t n = Prob.getNumerator();
>> uint32_t d = Prob.getDenominator();
>>
>> + // Limit the result to 1; 0 is a sentinel value. This keeps BlockFrequencyInfo
>> + // from getting stuck at zero frequencies just because a value became too
>> + // small to be represented as a BlockFrequency.
>> + Frequency = (n == 0 || Frequency != 0) ? Frequency : 1;
>
> Can branch probabilities be zero? If they can, we probably shouldn’t take that value seriously either.
They can, and I wanted to keep the invariant that
BlockFrequency(0) * x = 0
x * BranchProbability(0, y) = 0
All other results will be >= 1 now.
- Ben
More information about the llvm-commits
mailing list