Skip to content
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

JIT: Optimize struct parameter register accesses in the backend #110819

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

jakobbotsch
Copy link
Member

This PR adds an optimization in lowering to utilize the new parameter
register to local mappings added in #110795. The optimization detects IR
that is going to result in stack spills/loads and instead replaces them
with scalar locals that will be able to stay in registers.

Physical promotion benefits especially from this as it creates the kind
of IR that the optimization ends up kicking in for. The heuristics of
physical promotion are updated to account for the fact that the backend
is now able to do this optimization, making physical promotion more
likely to promote struct parameters.

Based on #110795

This PR adds an optimization in lowering to utilize the new parameter
register to local mappings added in dotnet#110795. The optimization detects IR
that is going to result in stack spills/loads and instead replaces them
with scalar locals that will be able to stay in registers.

Physical promotion benefits especially from this as it creates the kind
of IR that the optimization ends up kicking in for. The heuristics of
physical promotion are updated to account for the fact that the backend
is now able to do this optimization, making physical promotion more
likely to promote struct parameters.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 18, 2024
@MichalPetryka
Copy link
Contributor

Does this fix #89374?

@jakobbotsch
Copy link
Member Author

Does this fix #89374?

No -- currently I'm just looking at ensuring that physical promotion is able to handle the cases that old promotion can handle. This change should only result in a small number of diffs since old promotion handles the vast majority of structs passed in registers today, but it gets us closer to removing old promotion entirely.
The representation should be flexible enough to allow us to improve cases like #89374 in the future though.

For GC refs in structs these have to be zeroed anyway, so we might as
well just spill to the original parameter as well as the new mapping.
This means we can avoid the manually inserted spill in the init block,
and we retain the property that parameters are fully defined by the
prolog.
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

Successfully merging this pull request may close these issues.

2 participants