Skip to content

JIT: enable inlining of IL stubs with EH#118140

Closed
AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:R2REHInlining
Closed

JIT: enable inlining of IL stubs with EH#118140
AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:R2REHInlining

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Also, bail out of inlining analysis early if the pinvoke call was marked as unmanaged during initial pinvoke analysis.

Closes #113742

Also, bail out of inlining analysis early if the pinvoke call was marked as
unmanaged during initial pinvoke analysis.

Closes dotnet#113742
Copilot AI review requested due to automatic review settings July 28, 2025 20:54
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 28, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 enables the JIT to inline P/Invoke IL stubs that contain exception handling (EH) by removing a previous restriction. The change also adds early bailout logic to avoid unnecessary inlining analysis for calls already marked as unmanaged during P/Invoke analysis.

Key changes:

  • Adds new inline observation type for unmanaged code detection
  • Introduces early bailout for unmanaged calls in inlining analysis
  • Removes restriction preventing inlining of P/Invoke stubs with exception handling

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/inline.def Adds IS_UNMANAGED observation type for fatal inline rejection
src/coreclr/jit/importercalls.cpp Adds early unmanaged call detection and removes P/Invoke EH inlining restriction


if (methAttr & CORINFO_FLG_PINVOKE)
{
// We should have already ruled out cases where we can directly call the unamanged method.

Copilot AI Jul 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a spelling error in the comment: 'unamanged' should be 'unmanaged'.

Suggested change
// We should have already ruled out cases where we can directly call the unamanged method.
// We should have already ruled out cases where we can directly call the unmanaged method.

Copilot uses AI. Check for mistakes.
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@MihuBot

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Still assessing this one, not sure we want to enable the extra inlining.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

NAOT size impact is a small net decrease, per MichalStrehovsky/rt-sz#153

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@jkotas any opinion on whether this is worth doing on its own? Based on the above I would say no, there's not much benefit.

Seems like we should sort out the schizophrenia around stub inlining in the JIT first, but I'm somewhat reluctant to churn those code paths at this point in the release.

@jkotas

jkotas commented Jul 30, 2025

Copy link
Copy Markdown
Member

Seems like we should sort out the schizophrenia around stub inlining in the JIT first

Yes, I agree.

It is fine to postpone it to .NET 11. This is not fixing any regressions.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Opened #118220 to track sorting out the inlining logic.

@github-actions github-actions Bot locked and limited conversation to collaborators Aug 30, 2025
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.

Investigate R2R issue when inlining methods with EH

3 participants