Skip to content

Handle KilledRegisters more efficiently in LinearScan::processKills() #112962

Closed

Description

@DeepakRajendrakumaran

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

  1. ghost added
    needs-area-label
    on Feb 26, 2025
  2. added
    untriaged
    on Feb 26, 2025
  3. jakobbotsch commented on Feb 26, 2025

    @jakobbotsch
    Member

    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.

  4. DeepakRajendrakumaran commented on Feb 26, 2025

    @DeepakRajendrakumaran
    ContributorAuthor

    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

  5. jakobbotsch commented on Feb 26, 2025

    @jakobbotsch
    Member

    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:

  6. added
    area-CodeGen-coreclr
    and removed
    needs-area-label
    on Feb 27, 2025
  7. dotnet-policy-service commented on Feb 27, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  8. removed
    untriaged
    on Mar 6, 2025
  9. added this to the 10.0.0 milestone on Mar 6, 2025
  10. DeepakRajendrakumaran commented on Mar 6, 2025

    @DeepakRajendrakumaran
    ContributorAuthor

    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:

    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 :)

  11. DeepakRajendrakumaran commented on Mar 17, 2025

    @DeepakRajendrakumaran
    ContributorAuthor

    @jakobbotsch @kunalspathak I have experimented a fair bit with your idea - https://github.com/dotnet/runtime/pull/111004/commits

    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.

    The best results I obtained was using lazy updates for minopts path(allocateRegistesrMinimal) and sticking to earlier for fullOpts(allocateRegisters) - https://github.com/dotnet/runtime/pull/111004/files

  12. DeepakRajendrakumaran commented on Mar 28, 2025

    @DeepakRajendrakumaran
    ContributorAuthor

    I ended up going a slightly different route with this since updatingFixedRefs lazily caused regression on fullOpt path

    The related PR has merged - #113713

  13. locked and limited conversation to collaborators on Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions