[PATCH] Assign a low branch weight to ASan's slow path.

Kostya Serebryany kcc at google.com
Fri Aug 29 09:06:08 PDT 2014


I am actually surprised too :)
We've used branch weights in a couple of other places but not here.
One can easily create a benchmark where these weights will lead to a
performance loss,
but the average SPEC numbers clearly show the overal benefit.
Let me submit this patch once I confirm the SPEC/ref numbers (the SPEC/test
numbers I saw yesterday are very nice)

--kcc


On Fri, Aug 29, 2014 at 1:57 AM, Chandler Carruth <chandlerc at google.com>
wrote:

> Adding ASan folks...
>
> Didn't we already look at this Kostya? A bit surprised this wasn't already
> the case.
>
>
> On Fri, Aug 29, 2014 at 1:24 AM, Jonas Wagner <jonas.wagner at epfl.ch>
> wrote:
>
>> Experiments on the SPEC benchmarks show that the slow path is rarely
>> taken, and that branch weights reduce branch misses and overall runtime.
>> ---
>>  lib/Transforms/Instrumentation/AddressSanitizer.cpp | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp
>> b/lib/Transforms/Instrumentation/AddressSanitizer.cpp
>> index 357b5d5..3ff0a61 100644
>> --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp
>> +++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp
>> @@ -870,8 +870,11 @@ void AddressSanitizer::instrumentAddress(Instruction
>> *OrigIns,
>>    TerminatorInst *CrashTerm = nullptr;
>>
>>    if (ClAlwaysSlowPath || (TypeSize < 8 * Granularity)) {
>> +    // We use branch weights for the slow path check, to indicate that
>> the slow
>> +    // path is rarely taken. This seems to be the case for SPEC
>> benchmarks.
>>      TerminatorInst *CheckTerm =
>> -        SplitBlockAndInsertIfThen(Cmp, InsertBefore, false);
>> +        SplitBlockAndInsertIfThen(Cmp, InsertBefore, false,
>> +            MDBuilder(*C).createBranchWeights(1, 100000));
>>      assert(dyn_cast<BranchInst>(CheckTerm)->isUnconditional());
>>      BasicBlock *NextBB = CheckTerm->getSuccessor(0);
>>      IRB.SetInsertPoint(CheckTerm);
>> --
>> 2.1.0
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140829/f5cb4305/attachment.html>


More information about the llvm-commits mailing list