Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JIT: Avoid recording uncanonicalizable loops #115223

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
May 1, 2025

Conversation

jakobbotsch
Copy link
Member

The example has a loop whose header is the beginning of a 'finally' clause and whose backedge is a CALLFINALLY edge. It is not possible to canonicalize such a loop: creating a new preheader will result in a new beginning of the finally clause, and by IR invariants the CALLFINALLY edge must jump to it. But that means the CALLFINALLY edge is no longer a backedge.

The loop structure here is spurious and arises because of two-pass EH, so it is unlikely we will lose much by just discarding these cases.

Fix #114869

The example has a loop whose header is the beginning of a 'finally'
clause and whose backedge is a CALLFINALLY edge. It is not possible to
canonicalize such a loop: creating a new preheader will result in a new
beginning of the finally clause, and by IR invariants the CALLFINALLY
edge must jump to it. But that means the CALLFINALLY edge is no longer a
backedge.

The loop structure here is spurious and arises because of two-pass EH,
so it is unlikely we will lose much by just discarding these cases.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 1, 2025
Copy link
Contributor

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

@jakobbotsch jakobbotsch marked this pull request as ready for review May 1, 2025 14:55
@Copilot Copilot AI review requested due to automatic review settings May 1, 2025 14:55
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS @BruceForstall

No diffs

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 a JIT issue where loops that have their header in a 'finally' clause and backedges from CALLFINALLY edges cannot be canonicalized, and discards these cases.

  • Updated the loop recording in FlowGraphNaturalLoops::Find() to include a canonicalizability check.
  • Added the IsLoopCanonicalizable() helper function in flowgraph.cpp and declared it in compiler.h, with an updated comment explaining its purpose.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/flowgraph.cpp Added IsLoopCanonicalizable() and updated loop condition in Find()
src/coreclr/jit/compiler.h Declared IsLoopCanonicalizable() and updated loop header comment
Comments suppressed due to low confidence (1)

src/coreclr/jit/flowgraph.cpp:4882

  • Consider adding unit tests to verify that loops with CALLFINALLY backedges are correctly marked as uncanonicalizable. This will help ensure that future changes do not reintroduce canonicalization issues for such loops.
if (!FindNaturalLoopBlocks(loop, worklist) || !IsLoopCanonicalizable(loop))

@jakobbotsch jakobbotsch merged commit 0729de5 into dotnet:main May 1, 2025
109 checks passed
@jakobbotsch jakobbotsch deleted the fix-114869 branch May 1, 2025 18:18
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 '!"BBJ_EHFINALLYRET predecessor of block that doesn't follow a BBJ_CALLFINALLY!"'
3 participants