Skip to content

Conversation

AndyAyersMS
Copy link
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 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
Copy link
Contributor

@Copilot Copilot AI left a 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 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.
Copy link

Copilot AI Jul 28, 2025

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.

Copy link
Contributor

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

@AndyAyersMS
Copy link
Member Author

@MihuBot

@AndyAyersMS
Copy link
Member Author

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

@AndyAyersMS
Copy link
Member Author

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

@AndyAyersMS
Copy link
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
Copy link
Member

jkotas commented Jul 30, 2025

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
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

2 participants