Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RyuJIT: representation of spill/unspill in JIT IR #92207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BruceForstall opened this issue Sep 18, 2023 · 3 comments
Open

RyuJIT: representation of spill/unspill in JIT IR #92207

BruceForstall opened this issue Sep 18, 2023 · 3 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@BruceForstall
Copy link
Member

Currently, LSRA annotates a tree node with GTF_SPILL if it should be spilled by the code generator after it is evaluated, and GTF_SPILLED if it must be reloaded before being used. This means that the actual generated set of loads and stores are not explicit in the IR as normal IR nodes. There ends up being a lot of special handling for SPILL/SPILLED flags, especially for multi-reg nodes.

Could we change LSRA to instead generate actual IR nodes for the spills and unspills (e.g., a GT_STORE_LCL_VAR for a store)? Then, the spill/unspill concept would be isolated to the register allocator, we could get rid of GTF_SPILL/GTF_SPILLED flags, as well as all the multi-reg spill cases, such as MultiRegSpillFlags, GetRegSpillFlagByIdx, etc. Presumably spills/unspills could then be subject to normal code motion optimizations (e.g., hoisting) (assuming we ever implemented post-LSRA optimizations).

@dotnet/jit-contrib Comments?

@BruceForstall BruceForstall added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 18, 2023
@BruceForstall BruceForstall added this to the 9.0.0 milestone Sep 18, 2023
@ghost
Copy link

ghost commented Sep 18, 2023

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

Issue Details

Currently, LSRA annotates a tree node with GTF_SPILL if it should be spilled by the code generator after it is evaluated, and GTF_SPILLED if it must be reloaded before being used. This means that the actual generated set of loads and stores are not explicit in the IR as normal IR nodes. There ends up being a lot of special handling for SPILL/SPILLED flags, especially for multi-reg nodes.

Could we change LSRA to instead generate actual IR nodes for the spills and unspills (e.g., a GT_STORE_LCL_VAR for a store)? Then, the spill/unspill concept would be isolated to the register allocator, we could get rid of GTF_SPILL/GTF_SPILLED flags, as well as all the multi-reg spill cases, such as MultiRegSpillFlags, GetRegSpillFlagByIdx, etc. Presumably spills/unspills could then be subject to normal code motion optimizations (e.g., hoisting) (assuming we ever implemented post-LSRA optimizations).

@dotnet/jit-contrib Comments?

Author: BruceForstall
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: 9.0.0

@jakobbotsch
Copy link
Member

I like the idea. It would be interesting to collect data on the number of spills/unspills we see (with/without minopts) to get an idea of how much additional IR it would introduce.

Would the new nodes have their own codegen or would they be handled as part of the consuming node? For example, GT_RELOAD already exists today with the latter semantics, from lsra-detail.md:

... if the value must be reloaded to a different register than the one specified on the tree node (which is the one used when the node is evaluated), LSRA must insert a GT_RELOAD node to specify the register to which it should be reloaded.

which sounds very similar to this idea.

It is not completely obvious to me what the IR nodes would end up looking like, especially for the multireg node cases. Do you have any examples of what you were thinking?

There is also the question of how reg-optional uses would be represented, e.g. GenTree::isUsedFromSpillTemp today relies on GTF_SPILLED. Perhaps LSRA could rephrase these uses in terms of containment, so that it would replace spilled reg-optional operands with a contained GT_UNSPILL/GT_RELOAD.

@BruceForstall
Copy link
Member Author

Definitely some more research is needed here.

I would expect the new nodes would have their own codegen and would not be contained.

GT_RELOAD is already used, but only in some situations where the GTF_SPILLED bit couldn't be used (IIUC).

Thanks for pointing out the isUsedFromSpillTemp case: it seems like that, too, should be removed. LSRA should insert the correct reference (maybe a new GT_TEMP_VAR if necessary? or LCL_VAR with a distinguished varNum (negative)?)

@JulieLeeMSFT JulieLeeMSFT modified the milestones: 9.0.0, 10.0.0 Jul 25, 2024
@BruceForstall BruceForstall modified the milestones: 10.0.0, Future Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

No branches or pull requests

3 participants