Skip to content

Fix interpreter compiler branch elimination#120768

Merged
janvorli merged 1 commit intodotnet:mainfrom
janvorli:fix-interpreter-branch-elimination
Oct 16, 2025
Merged

Fix interpreter compiler branch elimination#120768
janvorli merged 1 commit intodotnet:mainfrom
janvorli:fix-interpreter-branch-elimination

Conversation

@janvorli
Copy link
Member

The code emission was eliminating branches at the end of a basic block going to the next basic block. This should only happen in case when both blocks are on the same overlapping clause depth though. It was breaking couple of EH tests where it let execution flow from the end of a try block to an unrelated block.

The code emission was eliminating branches at the end of a basic block
going to the next basic block. This should only happen in case when both
blocks are on the same overlapping clause depth though.
It was breaking couple of EH tests where it let execution flow from the
end of a try block to an unrelated block.
@janvorli janvorli added this to the 11.0.0 milestone Oct 15, 2025
@janvorli janvorli self-assigned this Oct 15, 2025
@janvorli janvorli requested a review from BrzVlad as a code owner October 15, 2025 20:18
@janvorli janvorli requested a review from kg as a code owner October 15, 2025 20:18
Copilot AI review requested due to automatic review settings October 15, 2025 20:18
Copy link
Contributor

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 fixes a bug in the interpreter compiler's branch elimination optimization. The compiler was incorrectly removing branches to the next basic block without considering exception handling (EH) clause boundaries, which broke exception handling tests by allowing execution to flow incorrectly from try blocks into unrelated blocks.

Key Changes:

  • Added an exception handling clause depth check to the branch elimination condition
  • Updated the comment to clarify when branch elimination is safe

@dotnet-policy-service
Copy link
Contributor

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

@BrzVlad
Copy link
Member

BrzVlad commented Oct 16, 2025

I think it would be nice at some point to have the pNextBB in the order we actually emit the bblocks, not sure how trivial it is though. Debug code dumping outputs code in a different order than the final code when EH is involved. Might also simplify some other things in the future.

@janvorli
Copy link
Member Author

think it would be nice at some point to have the pNextBB in the order we actually emit the bblocks

I'll try to figure out something.

@janvorli janvorli merged commit ccf1a58 into dotnet:main Oct 16, 2025
97 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants