Improve allocateRegisters() and allocateRegistersMinimal() by representing and accessing local register sets in a more efficient manner
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cpp
- Domain
- compilers, performance
Research direction
Start in src/coreclr/jit/lsra.cpp at the allocateRegisters() code around the referenced local register masks, then trace allocateRegistersMinimal() and freeRegisters(). Compare the proposed RegSetMasks representations and inspect how SingleTypeRegSet is used. Done means the affected methods avoid the reported more-than-64-register overhead while preserving register allocation behavior and improving the listed regressions.
Written by the indexing model from the issue text.
Description
In allocateRegisters() and allocateRegistersMinimal(), we iterate through RefPositions and update regsToFree, delayRegsToFree, regsToMakeInactive, delayRegsToMakeInactive and copyRegsToFree. These are regMaskTP local variables and as such incurs significant regression with more than 64 registers.
This primarily applies to the following
regMaskTP regsToFree = RBM_NONE;
regMaskTP delayRegsToFree = RBM_NONE;
regMaskTP regsToMakeInactive = RBM_NONE;
regMaskTP delayRegsToMakeInactive = RBM_NONE;
regMaskTP copyRegsToFree = RBM_NONE;
In order to optimize the operations on these variables, they can be represented by
struct RegSetMasks
{
SingleTypeRegSet regsToFree = RBM_NONE;
SingleTypeRegSet delayRegsToFree = RBM_NONE;
SingleTypeRegSet regsToMakeInactive = RBM_NONE;
SingleTypeRegSet delayRegsToMakeInactive = RBM_NONE;
SingleTypeRegSet copyRegsToFree = RBM_NONE;
};
and declared as one of following
Option A
RegSetMasks lowRegSet;
RegSetMasks highRegSet;
RegSetMasks *currRegSet = &lowRegSet;
Option B
RegSetMasks intRegSet;
RegSetMasks fltRegSet;
RegSetMasks mskRegSet;
This will reduce the overhead due to operations on regMaskTP since we will be working on SingleTypeRegSet which is a uint64.
Methods from the list of regressed methods this is likely to improve
allocateRegisters()allocateRegistersMinimal()freeRegisters()
The effect of switching to more than 64 registers for these methods without an optimization based on profiling is shown below.
| Method | InsCountDiff | InsPercentageDiff | ContributionPercentage |
|---|---|---|---|
| allocateRegistersMinimal@LinearScan | 3524107314 | 33.71% | 10.36% |
| allocateRegisters@LinearScan | 2453448194 | 23.65% | 7.21% |
| freeRegisters@LinearScan | 1676484336 | 62.85% | 4.93% |
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·