[llvm-commits] [llvm] r136222 - /llvm/trunk/lib/Support/BlockFrequency.cpp

Andrew Trick atrick at apple.com
Wed Jul 27 10:47:01 PDT 2011


On Jul 27, 2011, at 9:50 AM, Chris Lattner wrote:

> 
> On Jul 27, 2011, at 9:00 AM, Jakub Staszak wrote:
> 
>> Author: kuba
>> Date: Wed Jul 27 11:00:40 2011
>> New Revision: 136222
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=136222&view=rev
>> Log:
>> Optimize 96-bit division a little bit.
> 
> How about:
>  if (top_part1 == 0 && top_part2 == 0) 
>    return low1/low2;
>  .. slow path..
> ?
> 
> -Chris


div96bit is currently just a local helper. Kuba already checks for 64-bit overflow before calling it.

But it does seem like it would be better to do mult96bit then check the top_part instead of UINT64_MAX / n.

 if (n > 0 && Frequency > UINT64_MAX / n) {
    // 96-bit value represented as W[1]:W[0].
    uint64_t W[2];

    // Probability is less or equal to 1 which means that results must fit
    // 64-bit.
    mult96bit(Frequency, n, W);
    Frequency = div96bit(W, d);

-Andy

> 
>> 
>> Modified:
>>   llvm/trunk/lib/Support/BlockFrequency.cpp
>> 
>> Modified: llvm/trunk/lib/Support/BlockFrequency.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/BlockFrequency.cpp?rev=136222&r1=136221&r2=136222&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Support/BlockFrequency.cpp (original)
>> +++ llvm/trunk/lib/Support/BlockFrequency.cpp Wed Jul 27 11:00:40 2011
>> @@ -46,8 +46,9 @@
>> uint64_t div96bit(uint64_t W[2], uint32_t D) {
>>  uint64_t y = W[0];
>>  uint64_t x = W[1];
>> +  int i;
>> 
>> -  for (int i = 1; i <= 64; ++i) {
>> +  for (i = 1; i <= 64 && x; ++i) {
>>    uint32_t t = (int)x >> 31;
>>    x = (x << 1) | (y >> 63);
>>    y = y << 1;
>> @@ -57,7 +58,7 @@
>>    }
>>  }
>> 
>> -  return y;
>> +  return y << (64 - i + 1);
>> }
>> 
>> }
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list