Skip to content

JIT: Propagate GC safe point flag in fgSplitBlockAtBeginning #116718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025

Conversation

amanasifkhalid
Copy link
Member

Fixes #116704 (comment). From that failure in particular, we have the following flowgraph before loop inversion runs:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------
BBnum BBid ref try hnd preds           weight   [IL range]   [jump]                            [EH region]        [flags]
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
BB01 [0000]  1                             1    [000..004)-> BB03(0.5),BB02(0.5)     ( cond )                   i
BB02 [0001]  1       BB01                  1    [004..005)                           (return)                   i
BB03 [0002]  1       BB01                  1    [005..04E)-> BB05(1)                 (always)                   i hascall gcsafe newobj
BB04 [0003]  1       BB05                  1    [04E..063)-> BB05(1)                 (always)                   i hascall gcsafe idxlen bwd bwd-target
BB05 [0004]  2       BB03,BB04             1    [063..06A)-> BB04(0.5),BB06(0.5)     ( cond )                   i bwd bwd-src
BB06 [0005]  1       BB05                  1    [06A..0B9)                           (throw )                   i hascall gcsafe newobj
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

BB06 has a tail call, and is flagged as having a GC safe point. It is also the exit block of a loop headed by BB05. Loop inversion gives BB06 an empty predecessor to keep the loop canonical by calling fgSplitBlockAtBeginning. This calls fgSplitBlockAtEnd, which removes the safe point flag on the new block since it initially keeps the code in the predecessor. fgSplitBlockAtBeginning does not reset the flag after moving the code into the new successor. Thus, we end up with the following flowgraph:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------
BBnum BBid ref try hnd preds           weight   [IL range]   [jump]                            [EH region]        [flags]
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
BB01 [0000]  1                             1    [000..004)-> BB03(0.5),BB02(0.5)     ( cond )                   i
BB02 [0001]  1       BB01                  1    [004..005)                           (return)                   i
BB03 [0002]  1       BB01                  1    [005..04E)-> BB09(0.5),BB08(0.5)     ( cond )                   i hascall gcsafe newobj
BB08 [0021]  1       BB03                  1    [???..???)-> BB04(1)                 (always)                   i hascall newobj
BB04 [0003]  2       BB04,BB08             1    [04E..06A)-> BB04(0.5),BB06(0.5)     ( cond )                   i hascall gcsafe idxlen bwd bwd-target
BB06 [0005]  1       BB04                  1    [???..???)-> BB09(1)                 (always)                   i hascall gcsafe newobj
BB09 [0022]  2       BB03,BB06             1    [06A..0B9)                           (throw )                   i hascall newobj
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Note the presence of the flag on BB06, which has no IR, and the lack of the flag on BB09, which contains the actual tail call.

@Copilot Copilot AI review requested due to automatic review settings June 16, 2025 22:17
@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 Jun 16, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #116704 by ensuring the GC safe point flag is correctly propagated during block splitting in loop inversion transformations. Key changes include copying the GC safe point flag to the new block and then removing it from the original block to correctly designate the tail-call block.

Comments suppressed due to low confidence (2)

src/coreclr/jit/fgbasic.cpp:4928

  • Ensure that copying the GC safe point flag from the current block to the new block correctly reflects the tail-call semantics. Consider adding a unit test to verify the flag propagation behaves as intended in loop inversion scenarios.
newBlock->CopyFlags(curr, BBF_GC_SAFE_POINT);

src/coreclr/jit/fgbasic.cpp:4929

  • Verify that removing the GC safe point flag from the current block does not disrupt related GC or tail-call handling mechanisms. Additional tests covering edge cases would help ensure that this change maintains correct behavior.
curr->RemoveFlags(BBF_GC_SAFE_POINT);

Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@amanasifkhalid
Copy link
Member Author

@dotnet/jit-contrib PTAL. Diffs show about 200 contexts with changes in interruptibility per platform. Thanks!

@amanasifkhalid
Copy link
Member Author

ping @dotnet/jit-contrib

@amanasifkhalid
Copy link
Member Author

/ba-g unrelated failure

@amanasifkhalid amanasifkhalid merged commit 46046a3 into dotnet:main Jun 17, 2025
108 of 110 checks passed
@amanasifkhalid amanasifkhalid deleted the safe-point-flag branch June 17, 2025 20:57
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.

Assertion failed 'comp->compCurBB->HasFlag(BBF_GC_SAFE_POINT) || comp->fgFirstBB->HasFlag(BBF_GC_SAFE_POINT)' during 'Lowering nodeinfo'
2 participants