Skip to content

Comments

Do not consider InUse registers for assigning to consecutive candidates#95612

Merged
kunalspathak merged 5 commits intodotnet:mainfrom
kunalspathak:encode-utf8
Dec 5, 2023
Merged

Do not consider InUse registers for assigning to consecutive candidates#95612
kunalspathak merged 5 commits intodotnet:mainfrom
kunalspathak:encode-utf8

Conversation

@kunalspathak
Copy link
Contributor

When checking if consecutive registers are available, also take into account the information if registers are in use at the same location. If that is the case, do not consider it as candidate for consecutive register allocation.

I also experimented with 6e8b096 to not spill a register that is already assigned to the consecutive registers because that could involve lot of moving around, since the next consecutive registers might have to be in different registers than the ones they were originally obtained. It doesn't make much difference in the codegen of the example of the code that was introduced in #95513 . I might revert depending on how CI and TP impact is.

image

 
Details: #95513 (comment)

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 4, 2023
@ghost ghost assigned kunalspathak Dec 4, 2023
@ghost
Copy link

ghost commented Dec 4, 2023

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

Issue Details

When checking if consecutive registers are available, also take into account the information if registers are in use at the same location. If that is the case, do not consider it as candidate for consecutive register allocation.

I also experimented with 6e8b096 to not spill a register that is already assigned to the consecutive registers because that could involve lot of moving around, since the next consecutive registers might have to be in different registers than the ones they were originally obtained. It doesn't make much difference in the codegen of the example of the code that was introduced in #95513 . I might revert depending on how CI and TP impact is.

image

 
Details: #95513 (comment)

Author: kunalspathak
Assignees: kunalspathak
Labels:

area-CodeGen-coreclr

Milestone: -

@kunalspathak kunalspathak changed the title Encode utf8 Do not consider InUse registers for assigning to consecutive candidates Dec 4, 2023
@kunalspathak kunalspathak marked this pull request as ready for review December 5, 2023 01:50
@kunalspathak
Copy link
Contributor Author

@dotnet/jit-contrib

Comment on lines 11967 to 11973
else if (assignedInterval->getNextRefPosition()->needsConsecutive)
{
// if next refposition is part of consecutive registers and there is already a register
// assigned to it then do not reassign for currentRefPosition, because with that, other
// registers for the next consecutive register assignment would have to be copied to
// different consecutive registers since this register is busy from this point onwards.
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to run out of registers if there are a number of instrinsics defining consecutive registers and later using them, and in between we don't allow spilling them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was exactly on my mind and hence wanted to check if we find a case like that in CI. I think I will revert this portion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, I could actually have it record the spill cost as costlier, so those registers will be preferred if no other option is available. With that we do eliminate the extra copies and the code looks much better:

main vs. latest changes

image

skip spilling consecutive vs. latest changes

image

@kunalspathak kunalspathak merged commit 24ee598 into dotnet:main Dec 5, 2023
@kunalspathak kunalspathak deleted the encode-utf8 branch December 5, 2023 21:13
@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants