Skip to content

JIT: clear BBF_DONT_REMOVE on the new preheader in loop inversion - #136043

Merged
lewing merged 3 commits into
dotnet:mainfrom
lewing:lewing-wasm-jit-unreachable-kept-block
Oct 19, 2026
Merged

lewing merged 3 commits into
dotnet:mainfrom
lewing:lewing-wasm-jit-unreachable-kept-block

Conversation

@lewing

@lewing lewing commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Loop inversion splits the preheader with fgSplitBlockAtEnd, and the new preheader inherits BBF_DONT_REMOVE. When the old preheader is a catch handler entry and the loop condition later folds to false, the new block becomes unreachable but can't be removed. On Wasm its stale bbPreorderNum trips block order disagrees with preorder num in fgWasmControlFlow; other targets emit a dead int3/brk.

The old preheader stays the EH entry, so this clears the flag on the new block, as the OSR entry code in fgopt.cpp does. fgSplitBlockAtEnd itself must keep copying the flag, because loop canonicalization relies on it when splitting try entries.

Resolves #136041

SuperPMI: diffs (dead throw removals only)

Note

This PR description was drafted with GitHub Copilot.

…sm control flow

Loop inversion splits a catch handler entry with fgSplitBlockAtEnd; the new
preheader inherits BBF_DONT_REMOVE. If the loop later becomes unreachable,
fgRemoveBlocksOutsideDfsTree keeps that block as an empty throw, and Wasm
control flow (which lays out only DFS blocks) asserts that block order
disagrees with preorder numbers.

Before removing unreachable blocks for Wasm, clear BBF_DONT_REMOVE on
unreachable blocks that are not EH region entries or call-finally pairs.

Fixes dotnet#136041

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1324801d-f940-4cf8-83cc-634c4510d91f
@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 Oct 19, 2026
@azure-pipelines

azure-pipelines Bot commented Oct 19, 2026 •

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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1324801d-f940-4cf8-83cc-634c4510d91f
@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.

Replace the Wasm-only unreachable block cleanup with a fix at the source.
Loop inversion splits the preheader with fgSplitBlockAtEnd, and the new
preheader inherits BBF_DONT_REMOVE. When the old preheader is a handler
entry and the loop later becomes unreachable, the new block can't be
removed. Other targets emit it as a dead throw; Wasm control flow asserts.

The old preheader keeps its EH entry role, so the new block doesn't need
the flag.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1324801d-f940-4cf8-83cc-634c4510d91f
@lewing lewing changed the title [wasm] Remove unreachable blocks with stale BBF_DONT_REMOVE before Wasm control flow JIT: clear BBF_DONT_REMOVE on the new preheader in loop inversion Oct 19, 2026
@lewing
lewing marked this pull request as ready for review October 19, 2026 01:52
@lewing
lewing requested review from EgorBo and jakobbotsch October 19, 2026 17:47
@lewing
lewing enabled auto-merge (squash) October 19, 2026 22:42
@lewing

lewing commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

/ba-g failure looks like a very rare reoccurrence of #116753 not worth reopening unless it recurs more than once every 6+ months

@lewing
lewing merged commit c9cd52f into dotnet:main Oct 19, 2026
136 of 138 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 20, 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.

[wasm][R2R] JIT asserts "block order disagrees with preorder num" when an unremovable block becomes unreachable

2 participants