Skip to content

JIT: preserve post-call nops during late jump removal - #137261

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-late-jump-removal
Nov 11, 2026
Merged

AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-late-jump-removal

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Preserve a one-byte nop when late jump-to-next removal deletes a jump
immediately after a call. This keeps the call-return PC separate from a
branch target with different GC state, and preserves padding at EH boundaries.

#95493 allowed removing these jumps while retaining nops only
before OS epilogs. #95565 subsequently enabled asynchronous
interruption at call-return safepoints. The label-time padding check misses
the call when the removable jump is still present.

Adds a GC-liveness regression and EH-boundary coverage.

Validation

Windows x64, Checked CoreCLR with Release libraries and a matching Core_Root:

  • Checked JIT build and regression-test build passed.
  • GC regression: the unfixed JIT aborts with a corrupted OBJECTREF under targeted
    DOTNET_GCStress=4; the fixed JIT passes all three new cases.
  • Complete Regression_ro_2 runner: 491 passed.
  • jit-format: all nine Windows x64 configuration/project combinations passed.

SuperPMI

All 10 matching Windows x64 collections: 2,764,370 contexts, zero failures or
misses for either JIT. 1,439 contexts changed; total code size grew by 1,851
bytes (+0.000156%). No throughput benchmark was run.

Resolves #135384

Note

This PR was created with GitHub Copilot.

dotnet#95493 allowed removing post-call jumps to next without introducing
nops, keeping nops only before epilogs. Subsequently, dotnet#95565 enabled
asynchronous interruption at call-return safepoints, reintroducing the need for
post-call nop padding when the instruction after a call is a join and incoming GC
state differs from the call-return state.

Fixes dotnet#135384

Co-authored-by: Copilot <[email protected]>
@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 Nov 10, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@dotnet/jit-contrib ptal

Seems like we have gone back and forth on this, but the nops are needed in some cases.

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.

🟡 Changes recommended

The regression assertion passes even with the unfixed JIT, so an x64 codegen check is needed to detect missing EH-boundary padding and fail when the fix is reverted.

1 open issue
What changed in this PR

This PR fixes x64 JIT late jump removal so deleting a jump immediately after a call preserves a one-byte nop. This keeps call-return GC state separate from branch-target state and preserves exception-handling boundaries.

Changes:

  • Preserve post-call padding regardless of whether the target is an OS epilog.
  • Rename the jump flag and update emission checks and diagnostics.
  • Add GC-liveness regression cases and an exception-handler boundary test.
File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_135384.cs Adds GC-state and exception-handler test scenarios.
src/​coreclr/​jit/​emitxarch.cpp Tracks post-call jumps and emits replacement nops.
src/​coreclr/​jit/​emit.h Renames and documents the post-call jump flag.
src/​coreclr/​jit/​emit.cpp Retains one-byte padding during late jump removal and updates diagnostics.

Review effort: Balanced

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

@JulieLeeMSFT

Copy link
Copy Markdown
Member

LGTM. Jump removal runs after prolog/epilog generation and before distance binding and alignment, without an optimization-tier guard. The one-byte replacement is reflected in layout accounting and actual emission. Branches that remain cannot enter the NOP-emission path.

@AndyAyersMS
AndyAyersMS merged commit f598b38 into dotnet:main Nov 11, 2026
136 of 138 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 12, 2026
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.

JIT: (bug) late jump removal drops the NOP required after a call at the end of a try region (x64)

3 participants