Repository navigation
JIT: check reachability before simplifying dominated relop - #138624
Open
AndyAyersMS wants to merge 1 commit into
Open
AndyAyersMS wants to merge 1 commit into
AndyAyersMS wants to merge 1 commit into
Conversation
Redundant branch opts can rewrite a dominated relop to (relop AND dominating relop), which is only valid if the dominating relop holds whenever the block is reached. Verify the block is not reachable from the dominating block's shared successor, using a per-phase budget. Fixes dotnet#133980. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Member
Author
|
@jakobbotsch PTAL Note for normal flow this seems to require irreducible flow which likely explains why we didn't spot this sooner. |
jakobbotsch
approved these changes
Dec 2, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The optimization
Redundant branch opts can eliminate a dominating branch
Dwhen one of itssuccessors is a side-effect-free conditional block
Band the other is asuccessor
Xshared withB. The original optimization, introduced in#126587, removes
D's branch when the predicate takingBaway from
Ximplies the predicate takingDtoB.#127181 extended this to cases where the implication does not
hold. It combines those predicates with AND and, if that simplifies to a
relop over the same operands, removes
D's branch and rewritesB's relop.For example,
(x != y) && (x <= y)simplifies tox < y.The bug
DdominatingBdoes not mean that every execution ofBfollows theD-to-Bedge. In the regression test,Xcan reachBwithout revisitingD:For
x == y, the original flow isD -> X -> B -> return 1. The rewriteinstead makes
Dbranch unconditionally toBand changesB's test tox < y. Execution then cycles throughBandXuntil it returns-1.The conjunction is not valid at
Bbecausex != yneed not hold there.The fix
Before rewriting
B's relop, check whetherXcan reachBwithout passingthrough
D. Start atD's actual shared successor so the search alsoconsiders EH flow from skipped blocks. Allow the rewrite only when
Bisunreachable; otherwise, or if the shared per-phase reachability budget is
exhausted, leave the branches unchanged. Add regression coverage for equal,
less-than, and greater-than inputs.
Validation
.\src\tests\build.cmd -Test JIT\Regression_ro_2\Regression_ro_2.csproj x64 Checked: passed..\Regression_ro_2.cmd -coreroot C:\repos\runtime4\artifacts\tests\coreclr\windows.x64.Checked\Tests\Core_Rootfrom the built test directory: 527 passed, 7 skipped, including all three
regression cases.
compared contexts; 52,955 contexts were missing for both JITs. The baseline
was built at
5339d5292c9, whose JIT sources match the parent commit.benchmarks.run_pgousing Release non-PGO JITs:98,518 contexts compared, 408 missing for both; JIT instruction count
decreased by 0.0085%.
Resolves #133980
Note
This PR description was generated with GitHub Copilot.