Skip to content

JIT: Preserve exception order in loop hoisting - #133642

Open
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-133585-loop-hoist-exceptions
Open

JIT: Preserve exception order in loop hoisting#133642
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-133585-loop-hoist-exceptions

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Fixes #133585.

Loop hoisting previously kept its exception-ordering barrier open for an
invariant but non-hoistable throwing expression. This allowed a later throwing
expression to be hoisted ahead of it. Close the barrier whenever a throwing
expression cannot itself be hoisted.

Add coverage to the existing loop-hoisting exception-ordering regression test.

Validation:

  • build.cmd clr.jit -c checked
  • Regression_o_1: new case fails with the baseline JIT and passes with the changed JIT
  • Windows x64 Checked SuperPMI: 987,559 successful compilations, 0 failures, 42 context diffs across four collections, and effectively neutral aggregate PerfScore geomeans (-0.0000% to +0.0004%)

Note

This pull request description was generated with GitHub Copilot.

Loop hoisting could move a throwing expression ahead of an invariant but
non-hoistable throwing expression, changing the observed exception. Block
further side-effecting hoists whenever a throwing expression cannot itself be
hoisted.

Fixes dotnet#133585

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 69df99f0-1e6a-49a2-8061-9611e90c24bc
Copilot AI lite review requested due to automatic review settings September 10, 2026 21:51
@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 Sep 10, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 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 unresolved issues were identified in the reviewed changes.

Pull request overview

Fixes JIT loop-hoisting exception ordering by preventing later throwing expressions from being hoisted prematurely.

Changes:

  • Closes the hoisting barrier for non-hoistable throwing expressions.
  • Adds regression coverage for bounds-check and division exceptions.
File summaries
File Description
src/tests/JIT/Regression/JitBlue/GitHub_7147/GitHub_7147.cs Adds regression coverage verifying exception order.
src/coreclr/jit/optimizer.cpp Preserves exception ordering during loop hoisting.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

@AndyAyersMS

Copy link
Copy Markdown
Member Author

In this case we have an invariant bounds checked array access. Seems like we ought to be able to hoist such things, but we can't, and so we then need to block any other possible exception hoists.

@jakobbotsch PTAL
fyi @dotnet/jit-contrib

@AndyAyersMS

Copy link
Copy Markdown
Member Author

This fails the same way in 9, 10, and 11, so is not a recent regression.

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) Loop hoisting moves a throwing division above a bounds check, so the wrong exception is raised

2 participants