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: Improve inliner - static readonly fields, pinvokes, Span::Length #62421

Closed
wants to merge 11 commits into from

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Dec 5, 2021

Contributes to #59002

This PR:

  1. Recognizes static readonly fields of primitive types as potential constants => finds more potential foldable expressions/branches.
  2. Recognizes "pinvokes" in calls in order to avoid inlining of callees with them unless caller already have one - in this case we give callees with pinvokes additional boost to share the transition machinery.
  3. Mark ReadOnlySpan/Span::get_Length as [Intrinsic] - this simple change alone generates -6037 negative diff! 😮
  4. Drop too optimistic call(CNS, ...) -> CNS heuristic. Currently, if jit sees a call and suspects its first argument is a const - it assumes it is likely to become a constant too - this produced many false-positive "foldable branches" and a large diff as the result.
  5. Increases multiplier for foldable branches and intrinsics (e.g. fixes inlining of IsLatin1 into IsDigit here)

Jit-diff after these changes: Total bytes of delta: -292814 (-0.71 % of base) (jitutils, -f, crossgen2) - will post more detailed diffs soon.

TODO:

  • Test impact on throughput (from getMethodAttribs and getStaticFieldCurrentClass)
  • Test impact on TE benchmarks
  • Save final codegen size (or a least a single bit "codegen is likely small") during R2R to then pick up by tier1.
  • ARM64-specific tuning (ABI, more registers, etc).

1) recognize pinvokes
2) remove "CALL(cns,...) -> CNS" heuristic
3) mark Span/ReadOnlySpan get_Length as intrinsic
4) recognize "static readonly" fields of primitive types as constants
@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 5, 2021
@ghost
Copy link

ghost commented Dec 5, 2021

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

Issue Details

Contributes to #59002

This PR:

  1. Recognizes static readonly fields of primitive types as potential constants => finds more potential foldable expressions/branches.
  2. Recognizes "pinvokes" in calls in order to avoid inlining of callees with them unless caller already have one - in this case we give callees with pinvokes additional boost.
  3. Mark [ReadOnly]Span.get_Length as intrinsic - this simple change alone generates a large negative diff!
  4. Drop too optimistic "call(CNS, ...) -> CNS" heuristic. Currently if jit sees a call and suspect its first argument is a const - it assumes it is likely to become a consant too - this produced many false-positive "foldable branches".
  5. Increase multiplier for foldable branches and intrinsics.

Jit-diff after these changes: Total bytes of delta: -292814 (-0.71 % of base) (jitutils, -f, crossgen2) - will post more detailed diffs soon.

TODO:

  • Test impact on throughput (from getMethodAttribs and getStaticFieldCurrentClass)
  • Test impact on TE benchmarks
  • Save codegen size (or a least a single bit "codegen is likely small") during R2R to then pick up by tier1.
  • ARM64-specific tuning (ABI, more registers, etc).
Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@stephentoub
Copy link
Member

Mark ReadOnlySpan/Span::get_Length as [Intrinsic] - this simple change alone generates -6037 negative diff!

😉

@marek-safar
Copy link
Contributor

/cc @BrzVlad

@ghost ghost closed this Jan 23, 2022
@ghost
Copy link

ghost commented Jan 23, 2022

Draft Pull Request was automatically closed for inactivity. Please let us know if you'd like to reopen it.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 23, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

3 participants