Skip to content

[release/11.0] JIT: fix switch peeling stealing the wrong operand of its compare - #137375

Merged
JulieLeeMSFT merged 1 commit into
dotnet:release/11.0from
AndyAyersMS:backport-132395-release-11
Nov 13, 2026
Merged

JulieLeeMSFT merged 1 commit into
dotnet:release/11.0from
AndyAyersMS:backport-132395-release-11

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Fixes Issue #137330

main PR #132395

Description

Backport of #132395 to release/11.0.

Reuse the switch value before sequencing the dominant-case comparison, which can swap its operands. The JIT change is identical to the main-branch fix; the regression test uses an isolated project with tiered compilation and PGO enabled.

Customer Impact

  • Customer reported
  • Found internally

#137330 reports incorrect results on .NET 11.0.0: an unrolled switch can dispatch on the dominant case instead of the actual value. The report is on macOS ARM64; the issue also reproduces on Windows x64.

Regression

  • Yes
  • No

The issue remains in .NET 11 but was fixed in .NET 10.0.13 and later. The specific introducing change has not been established.

Testing

  • .\build.cmd clr+libs+host -c Checked -rc Checked -lc Release -hc Release — passed on the previous release tip; the subsequent release update changed only unrelated library tests.
  • .\src\tests\build.cmd -Test JIT\Regression\Regression_2.csproj x64 checked -Priority 1 -SkipNative /p:LibrariesConfiguration=Release /p:HostConfiguration=Release — passed, with one pre-existing IL warning in Runtime_74635.
  • .\build.cmd clr.jit -c Checked -rc Checked -lc Release -hc Release and .\src\tests\build.cmd -GenerateLayoutOnly x64 checked /p:LibrariesConfiguration=Release /p:HostConfiguration=Release — passed after updating to the latest release tip.
  • With CORE_ROOT set to the checked layout, & "$env:CORE_ROOT\..\..\JIT\Regression\JitBlue\Runtime_132370\Runtime_132370\Runtime_132370.cmd" failed as expected in 5/5 runs before the fix and passed 5/5 after it.
  • & "$env:CORE_ROOT\..\..\JIT\Regression\Regression_2\Regression_2.cmd" 'DisplayName~Runtime_132370' — passed one out-of-process test after the update, with Tier1 compilation confirmed.

The test was not run locally on macOS ARM64. Targeted JIT formatting and clang-tidy checks passed; the full jitformat.py sweep was not run.

Risk

Low: this is the same JIT change already in main and .NET 10, and it affects profile-guided switch peeling. The original PR reported no assembly diffs for its benchmark and library collections.

Resolves #137330

Note

This description was generated with GitHub Copilot.

Backport dotnet#132395 to release/11.0.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 58a22678-35fa-4b52-8f7f-563e0c9e37ce
@AndyAyersMS
AndyAyersMS requested a balanced review from Copilot November 11, 2026 19:19
@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 11, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@dotnet/jit-contrib PTAL

Fix that is in 10.0 and main, but missed being in 11.0.

@azure-pipelines

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

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

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.

🟢 Approval recommended

No active review issues are recorded, although builds and tests were not run during this review.

No open issues 🎉

What changed in this PR

Backports #132395 to release/11.0, addressing #137330: profile-guided switch peeling could reuse the dominant-case constant instead of the actual switch value after comparison operands were swapped.

Changes:

  • Reuses the switch value before sequencing the comparison and removes redundant rethreading.
  • Adds a regression test covering switch dispatch in an unrolled loop.
  • Runs the test in an isolated process with tiered compilation and profile-guided optimization enabled.

Builds and tests were not run during this review.

File Description
src/​tests/​JIT/​Regression/​JitBlue/​Runtime_132370/​Runtime_132370.csproj Configures the isolated, priority-1 regression test and tiering settings.
src/​tests/​JIT/​Regression/​JitBlue/​Runtime_132370/​Runtime_132370.cs Exercises dominant-case profiling and verifies correct switch results.
src/​coreclr/​jit/​fgopt.cpp Preserves the switch operand before comparison sequencing can swap operands.

Review effort: Balanced

@AndyAyersMS AndyAyersMS added this to the 11.0.0 milestone Nov 11, 2026
@AndyAyersMS AndyAyersMS added the Servicing-consider Issue for next servicing release review label Nov 11, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

fyi @JulieLeeMSFT

@JulieLeeMSFT JulieLeeMSFT added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Nov 13, 2026
@JulieLeeMSFT

Copy link
Copy Markdown
Member

/ba-g known issues.

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 Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: unrolled loop re-dispatches its switch with the index folded to 0 (not backported to .NET 11)

4 participants