You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handle KilledRegisters more efficiently in LinearScan::processKills() #112962
LinearScan::processKills() accounts for a good percentage of TP regression when adding additional registers as shown below
Method
InsCountDiff
InsPercentageDiff
ContributionPercentage
processKills@LinearScan
5849967774
114.36%
17.20%
LinearScan::processKills() obtains list of registers using RefPosition->getKilledRegisters(). This currently is a regMaskTP.
We do a number of expensive operations on this regMaskTP in a loop including the following - IsNonEmpty(), genFirstRegNumFromMaskAndToggle(), >=, &=. Explore possibility of storing killedRegisters as a SingleTypeRegSet and thus improve TP.
Activity
ghost added
needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
A lot of the cost here is coming from the fact that there are more registers to kill, hence the loop iterates many more times. The bit set operations may be a quite small proportion of this.
It would be more interesting to investigate making the "next kill location" lazily updated as we don't expect to need need that for the vast majority of registers.
A lot of the cost here is coming from the fact that there are more registers to kill, hence the loop iterates many more times. The bit set operations may be a quite small proportion of this. It would be more interesting to investigate making the "next kill location" lazily updated as we don't expect to need need that for the vast majority of registers.
Thanks for bringing this up. Kunal mentioned this too. I'll def look into it as well
So..I tried porting your changes and testing it out with latest main - 03da3d2
I do see some failures - specifically in some cases we do not resolve conflicts and end up asserting. I'm looking into it now. W.r.t improvements, I want to compare with this as base(This doesn't really add the new registers but is a dummy change which makes regMask bigger that uint64). Some initial tpdiff numbers show that your experiment improves performance but I'm loathe to put up the numbers till I fix the bugs since I can't be sure it's accurate :)
I do not think updating nextFixedRef lazily is an option for both minOpts and fullOpts paths.
For the minOpts path, updating lazily is perfect since we access nextFixedRef only for limited number of registers for each RefPosition
The fullOpts paths(allocateRegisters() and select()) tries to access nextFixedRef too many times. Especially during the selection heuristics where we iterate through candidates and gets nextFixedRef. At that point, just updating nextFixedRef the way we were doing earlier(when we encounter a kill or RefTypeFixedReg seems more efficient since we end up updating everytime we hit the heuristic anyway and if we switch to lazy update, instead of a simple lookup when running the heuristic, we end up calling getNextFixedRef with additional branches etc.
Activity
jakobbotsch commentedon Feb 26, 2025
A lot of the cost here is coming from the fact that there are more registers to kill, hence the loop iterates many more times. The bit set operations may be a quite small proportion of this.
It would be more interesting to investigate making the "next kill location" lazily updated as we don't expect to need need that for the vast majority of registers.
DeepakRajendrakumaran commentedon Feb 26, 2025
Thanks for bringing this up. Kunal mentioned this too. I'll def look into it as well
jakobbotsch commentedon Feb 26, 2025
I had an attempt at doing that last year (took me a while to find the code): https://github.com/dotnet/runtime/compare/main...jakobbotsch:runtime:lsra-lazy-fixed-ref?expand=1
I did not see the results I was expecting, but it may look better with more registers:
dotnet-policy-service commentedon Feb 27, 2025
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
DeepakRajendrakumaran commentedon Mar 6, 2025
So..I tried porting your changes and testing it out with latest main - 03da3d2
I do see some failures - specifically in some cases we do not resolve conflicts and end up asserting. I'm looking into it now. W.r.t improvements, I want to compare with this as base(This doesn't really add the new registers but is a dummy change which makes regMask bigger that uint64). Some initial tpdiff numbers show that your experiment improves performance but I'm loathe to put up the numbers till I fix the bugs since I can't be sure it's accurate :)
DeepakRajendrakumaran commentedon Mar 17, 2025
@jakobbotsch @kunalspathak I have experimented a fair bit with your idea - https://github.com/dotnet/runtime/pull/111004/commits
I do not think updating
nextFixedReflazily is an option for bothminOptsandfullOptspaths.For the
minOptspath, updating lazily is perfect since we accessnextFixedRefonly for limited number of registers for eachRefPositionThe fullOpts paths(allocateRegisters() and
select()) tries to accessnextFixedReftoo many times. Especially during the selection heuristics where we iterate through candidates and getsnextFixedRef. At that point, just updatingnextFixedRefthe way we were doing earlier(when we encounter a kill orRefTypeFixedRegseems more efficient since we end up updating everytime we hit the heuristic anyway and if we switch to lazy update, instead of a simple lookup when running the heuristic, we end up callinggetNextFixedRefwith additional branches etc.The best results I obtained was using lazy updates for
minoptspath(allocateRegistesrMinimal) and sticking to earlier for fullOpts(allocateRegisters) - https://github.com/dotnet/runtime/pull/111004/filesDeepakRajendrakumaran commentedon Mar 28, 2025
I ended up going a slightly different route with this since updatingFixedRefs lazily caused regression on fullOpt path
The related PR has merged - #113713