Skip to content

JIT: Modify switch and finally-ret successors using edge redirection helpers #117102

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 8 commits into from
Jun 30, 2025

Conversation

amanasifkhalid
Copy link
Member

Follow-up to #116933. By mutating the existing edge during switch successor modifications, we can avoid invalidating the unique switch successor map. Also adds a helper for removing edges from the switch successor map without needing to trash the whole entry. I'd like to get to a point where we always have accurate switch successor sets available -- we could even consider rearchitecting BBswtDesc to model BBehfDesc and hold unique successor edges.

@Copilot Copilot AI review requested due to automatic review settings June 27, 2025 20:36
@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 27, 2025
Copy link
Contributor

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

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 refines switch successor updates by mutating existing edges and adding helpers to remove specific switch desc map entries, avoiding full invalidations. Key changes include:

  • Replace full map invalidation with targeted edge removal in LowerSwitch.
  • Introduce GetDescriptorForSwitchIfAvailable and fgRemoveSuccFromSwitchDescMapEntry to manage switch successor sets.
  • Refactor fgReplaceEhfSuccessor to use fgRedirectEdge and a renamed removal helper for cleaner successor table updates.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/lower.cpp Use fgRemoveSuccFromSwitchDescMapEntry when peeling off the default case and invalidate only when needed.
src/coreclr/jit/fgflow.cpp Add GetDescriptorForSwitchIfAvailable and fgRemoveSuccFromSwitchDescMapEntry; deprecate global invalidation.
src/coreclr/jit/fgbasic.cpp Refactor fgReplaceEhfSuccessor to use edge redirection, rename fgRemoveEhfSuccessor, and optimize duplicate handling.
src/coreclr/jit/compiler.h Remove InvalidateUniqueSwitchSuccMap, declare new helpers, rename fgRemoveEhfSuccessor.

@amanasifkhalid
Copy link
Member Author

cc @dotnet/jit-contrib, @AndyAyersMS PTAL. Small diffs from floating-point precision changes around edge weights. Thanks!

@amanasifkhalid amanasifkhalid merged commit d0b2d08 into dotnet:main Jun 30, 2025
110 of 112 checks passed
@amanasifkhalid amanasifkhalid deleted the redirect-switch branch June 30, 2025 16:11
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.

2 participants