Coalesce duplicate spills and reloads per CFG block#2892
Merged
milan-tom merged 29 commits intooxcaml:mainfrom Aug 14, 2024
Merged
Coalesce duplicate spills and reloads per CFG block#2892milan-tom merged 29 commits intooxcaml:mainfrom
milan-tom merged 29 commits intooxcaml:mainfrom
Conversation
xclerc
reviewed
Aug 6, 2024
Contributor
|
(I have not read 96afa85 yet.) |
96afa85 to
d6d4a48
Compare
xclerc
reviewed
Aug 9, 2024
TheNumbat
reviewed
Aug 13, 2024
Member
TheNumbat
left a comment
There was a problem hiding this comment.
LGTM, Xavier's comments already cover my thoughts
ce5407b to
dbe4135
Compare
xclerc
approved these changes
Aug 14, 2024
Contributor
Author
|
Completed final checks and confirmed changes when optimization is disabled are only in files modified in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At present, if register allocation fails to register allocate a variable it is reloaded/spilled from the stack for every use throughout the duration of the whole program (either via creation of a new temporary register for that use or direct use in an instruction if the architecture supports this). This creates situations where even in a single CFG block the same variable may be reloaded and spilled many times. This can be avoided by using a register for that variable for the duration of a single block. This PR aims to do this by optimising the temporaries created after the first round of register allocation (only for this round to avoid infinite loops and the more rounds this optimisation is involved in the longer register allocation takes) to ensure at most one temporary register is used per variable in each CFG block.
Analysis of improvement (tested on compiler files)
Files
Functions
NB: Timing information is not analysed here as the files in the compiler are too small to do meaningful analyses of the worst cases.
The files/functions that have worse counts afterwards are due to assigning block temporaries for variables which have live ranges across a block that interfere with other registers which have already been register allocated. Future PR(s) will address this by disabling/tweaking the optimization in this case.
Full analysis (preview below)
