Skip to content

JIT: replace R2R EH-inlining workaround for PInvoke stubs#128790

Draft
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:R2REHInlining-revisit
Draft

JIT: replace R2R EH-inlining workaround for PInvoke stubs#128790
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:R2REHInlining-revisit

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

PR #112998 added a workaround blocking inline of PInvoke callees with EH, standing in for a missing crossgen2 version-resilience check. Jan fixed that in PR #115277, so the workaround is no longer needed.

Replace it with:

  • Early bail in impMarkInlineCandidateHelper when call->IsUnmanaged(). Rename CALLEE_HAS_UNMANAGED_CALLCONV to CALLEE_IS_UNMANAGED.
  • New GTF_CALL_M_PINVOKE_STUB_NO_INLINE, set by impCheckForPInvokeCall at the two cost-based bails (rarely-run, !impCanPInvokeInline) and honored by the inliner. Closes the cold-pinvoke case where the inliner would still inline the (larger) stub IL.

No SPMI asmdiffs. R2R version-resilience tests pass.

Fixes #113742.

PR dotnet#112998 added a workaround blocking inline of PInvoke callees with EH,
standing in for a missing crossgen2 version-resilience check. Jan fixed
that in PR dotnet#115277, so the workaround is no longer needed.

Replace it with:

* Early bail in impMarkInlineCandidateHelper when call->IsUnmanaged().
  Rename CALLEE_HAS_UNMANAGED_CALLCONV to CALLEE_IS_UNMANAGED.
* New GTF_CALL_M_PINVOKE_STUB_NO_INLINE, set by impCheckForPInvokeCall
  at the two cost-based bails (rarely-run, !impCanPInvokeInline) and
  honored by the inliner. Closes the cold-pinvoke case where the
  inliner would still inline the (larger) stub IL.

No SPMI asmdiffs. R2R version-resilience tests pass.

Fixes dotnet#113742.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 30, 2026 01:14
@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 May 30, 2026
Copy link
Copy Markdown
Contributor

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 narrows the JIT’s P/Invoke inlining behavior after the crossgen2 version-resilience fix, removing the broader EH-based workaround and adding a targeted callsite marker to prevent inlining P/Invoke IL stubs when P/Invoke inlining is disabled or not profitable.

Changes:

  • Renames the unmanaged-callee inline observation to reflect unmanaged code rather than call convention.
  • Adds a GTF_CALL_M_PINVOKE_STUB_NO_INLINE call flag and accessor.
  • Marks P/Invoke calls that should avoid IL stub inlining for ambient-disablement and cold-callsite cases, then honors that flag in inline candidate selection.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/inline.def Updates inline observation names/messages for unmanaged calls and P/Invoke stub no-inline decisions.
src/coreclr/jit/gentree.h Adds the new P/Invoke stub no-inline call flag and query helper.
src/coreclr/jit/importercalls.cpp Sets the new flag during P/Invoke import and uses it to reject affected inline candidates while removing the old EH workaround.

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.

Investigate R2R issue when inlining methods with EH

2 participants