[PATCH] Use Rvalue refs in APInt

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 15:24:28 PDT 2016


> On Jun 2, 2016, at 2:28 PM, Sanjoy Das <sanjoy at playingwithpointers.com> wrote:
> 
> On Wed, Jun 1, 2016 at 9:43 AM, Pete Cooper <peter_cooper at apple.com <mailto:peter_cooper at apple.com>> wrote:
> 
>> Another interesting data point is the compile time.  On my test case, SCEV::getRange is 8.9% of compile time which is a lot.  But of that, 6.3% is just in ConstantRange::multiply.  This method is heavy APInt code, and especially malloc traffic.
> 
> Yeah, that is definitely too high! Just to check: I assume you mean
> 8.9% of opt -O2 or something similar?
Yep, thats right.  ‘opt -O2 verify-uselistorder.bc -o opt.bc’.  The verify-uselistorder is the pre optimized, but post linked, bitcode when LTOing that tool.

BTW, I just looked at the latest numbers and the commits i’ve made so far save 3% of compile time on this use case.  So the 8.9% is more like 5.9% now.  And still a little more to come.
> 
>> Many of the speedup’s i’ve been finding involve doing less work (r271020 which avoids the latter half of ConstantRange::multiply and saves 3M allocations), and fixing cases of unnecessary APInt allocations (r270959).  This patch is along the same lines as the latter where we have malloc traffic we can avoid.
> 
> Making too many fixes on the APInt algorithms to avoid allocations
> seems like we're solving the issue at the wrong layer.  I think fixing
> infrastructural issues so that we _can_ be a little sloppy (within
> reason) in extending integers without thinking too much about malloc
> traffic is the right path.
I completely agree.  There are certainly limits to how far to push this.  For example, this code in ConstantRange::multiply:

  auto L = {this_min * Other_min, this_min * Other_max,
            this_max * Other_min, this_max * Other_max};

Once I have the Rvalue ref version of the APInt methods (a change which I think is reasonable), the above could be changed to:

  auto L = {this_min * Other_min, std::move(this_min) * Other_max,
            this_max * std::move(Other_min), std::move(this_max) * Other_max};

This would avoid 3 allocations out of 4 because we will then use the Rvalue APInt methods.  However, I think this might
be a little too much hacking.  So yeah, I totally agree with you, and hopefully we can solve cases like this one in a more
reasonable way than gratuitous use of std::move() or other APInt hackery :)
> 
> But you're doing the work, so you get to decide the path forward. :)
Sounds good to me :)
> 
> 
>> ConstantRange stats (bit width and count of hits in ConstantRange::ConstantRange)
> 
> This is great!  Is this a bootstrap of clang or something?
Actually same use case as before.  ‘opt -O2 verify-uselistorder’.  Its a nice small bit code which takes about 20s to optimize.
> 
> Btw, there are couple of bitwidths here that I find interesting, e.g.
> I'd not have expected this many i70 ConstantRange allocations.
Yeah, some of these are a bit surprising.  2^n and (2^n)+1 both seem likely due to the IR itself and SCEV, but anything else is a little odd.  I may take a look at the 258 bit case just because there are so many of them.

Pete
> 
> -- Sanjoy
> 
>> 1: 30850028
>> 2: 7238
>> 3: 5733
>> 4: 92
>> 5: 817
>> 6: 294
>> 7: 192
>> 8: 363498
>> 9: 896
>> 11: 330
>> 12: 378
>> 13: 385
>> 14: 125
>> 16: 30256
>> 18: 272
>> 20: 98
>> 24: 10
>> 25: 62
>> 26: 13
>> 27: 181
>> 28: 8
>> 31: 98
>> 32: 2003134
>> 33: 132
>> 34: 128
>> 36: 76
>> 38: 2130
>> 41: 3
>> 57: 262
>> 58: 244
>> 59: 342
>> 60: 2418
>> 61: 1211
>> 62: 190
>> 63: 226
>> 64: 5118228
>> 65: 128400
>> 66: 4236
>> 67: 14826
>> 68: 15408
>> 69: 13417
>> 70: 7959
>> 71: 347
>> 96: 88
>> 128: 364826
>> 129: 379580
>> 130: 19092
>> 256: 4734
>> 257: 19132
>> 258: 71826
>> 514: 4650
> 
> 
> 
> -- 
> Sanjoy Das
> http://playingwithpointers.com <http://playingwithpointers.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160602/89b367f2/attachment.html>


More information about the llvm-commits mailing list