-
Notifications
You must be signed in to change notification settings - Fork 5.1k
JIT: boost inlining for methods that may return small arrays #114806
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: boost inlining for methods that may return small arrays #114806
Conversation
Look for inlinees that may be allocating and returning small fixed sized arrays. When inlined, these array allocations may end up non-escaping and be stack allocated. This analysis is approximate; we can't tell for sure in the IL scan what the array size is, and we can't easily tell if the allocated array is actually returned. Contributes to dotnet#113236
@EgorBo FYI |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
@EgorBo PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the JIT inlining heuristics by adding a new observation for methods that may return small fixed-sized arrays, potentially enabling stack allocation of these arrays when inlined.
- Introduces a new flag (m_MayReturnSmallArray) in the inline policy.
- Marks inline observations based on array allocation in CEE_NEWARR cases to adjust the inlining multiplier.
- Updates XML dumping and multiplier determination logic to include the new observation.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/coreclr/jit/inlinepolicy.h | Added a new boolean flag for tracking small array returns. |
src/coreclr/jit/inlinepolicy.cpp | Implemented observation handling and updated multiplier. |
src/coreclr/jit/fgbasic.cpp | Integrated logic to detect array allocations in inline code. |
Files not reviewed (1)
- src/coreclr/jit/inline.def: Language not supported
Comments suppressed due to low confidence (1)
src/coreclr/jit/fgbasic.cpp:924
- [nitpick] Consider renaming 'isReturnsArrayKnown' to 'arrayTypeDetermined' or a similarly descriptive name to more clearly convey its purpose.
bool isReturnsArrayKnown = false;
@@ -1776,6 +1780,12 @@ double ExtendedDefaultPolicy::DetermineMultiplier() | |||
} | |||
} | |||
|
|||
if (m_MayReturnSmallArray) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might help maintainability to add a comment explaining why the multiplier is increased by 4.0 when a small array return is observed.
Copilot uses AI. Check for mistakes.
Seeing quite a few failures with
|
@AndyAyersMS I presume it fails on |
Yeah likely.... |
I wonder if you just can check I'm actually not sure why getClassAttribs gives up on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM assuming CI passes
Look for inlinees that may be allocating and returning small fixed sized arrays. When inlined, these array allocations may end up non-escaping and be stack allocated.
This analysis is approximate; we can't tell for sure in the IL scan what the array size is, and we can't easily tell if the allocated array is actually returned.
Contributes to #113236