JIT: fix liveness in throw helper blocks#124253
Conversation
PR dotnet#123781 changed things so that throw helper blocks are now created just after lower. Because of this they no longer get the special liveness update for unreachable blocks. Add this update in explicitly when the blocks are created. Fixes dotnet#123929
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
@jakobbotsch PTAL This will have a handful of diffs I will have two follow-on PRs once this merges:
Also will run some other pipelines once the main part of CI is done. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a JIT liveness bug where throw-helper blocks can be created after the point where the “unreachable blocks” liveness fixup runs, leaving those blocks with incorrect bbLiveIn/bbLiveOut state and potentially causing downstream GC/liveness issues (as seen in #123929).
Changes:
- Refactors the special throw-helper liveness update into a dedicated helper:
Compiler::fgSetThrowHelpBlockLiveness. - Reuses that helper from
Liveness<TLiveness>::DoLiveVarAnalysis()for blocks not present in the DFS tree. - Invokes the helper when a throw-helper block is created (
fgCreateThrowHelperBlock) to ensure correct liveness even if the block is created late.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/coreclr/jit/liveness.cpp | Extracts and centralizes throw-helper liveness fixup logic into fgSetThrowHelpBlockLiveness. |
| src/coreclr/jit/flowgraph.cpp | Applies the throw-helper liveness fixup immediately when creating a throw-helper block. |
| src/coreclr/jit/compiler.h | Declares the new fgSetThrowHelpBlockLiveness helper on Compiler. |
|
/azp run runtime-coreclr r2r-extra, runtime-coreclr gcstress0x3-gcstress0xc |
|
Azure Pipelines successfully started running 2 pipeline(s). |
jakobbotsch
left a comment
There was a problem hiding this comment.
LGTM.
I assume codegen is still implicitly referencing the throw helper blocks and that we thus cannot just run the liveness after they are created (i.e. it would require some special casing regardless of when we run it).
Correct. We never update the flow graph to show the flow to these helpers. We would need to split blocks or create some new way to describe mid-block branches. |
PR #123781 changed things so that throw helper blocks are now created just after lower. Because of this they no longer get the special liveness update for unreachable blocks.
Add this update in explicitly when the blocks are created.
Fixes #123929