Skip to content

Ignore PhiArgs without matching actual preds#125093

Merged
EgorBo merged 13 commits intodotnet:mainfrom
EgorBo:fix-optVisitReachingAssertions
Mar 4, 2026
Merged

Ignore PhiArgs without matching actual preds#125093
EgorBo merged 13 commits intodotnet:mainfrom
EgorBo:fix-optVisitReachingAssertions

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Mar 3, 2026

Fixes #124507

A couple of diffs

Copilot AI review requested due to automatic review settings March 3, 2026 01:41
@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 Mar 3, 2026
@dotnet-policy-service
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 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

Updates CoreCLR JIT’s assertion propagation through SSA PHI nodes to be more conservative when PHI arguments don’t correspond to actual CFG predecessors, and adds a regression test for #124507.

Changes:

  • Add a guard in optVisitReachingAssertions to abort PHI-based assertion inference when a PhiArg references a non-predecessor block.
  • Add a new JIT regression test Runtime_124507.
  • Wire the new test into Regression_ro_2.csproj.

Reviewed changes

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

File Description
src/coreclr/jit/compiler.hpp Abort PHI reaching-assertions walk when a PHI arg pred block is not an actual predecessor.
src/tests/JIT/Regression/Regression_ro_2.csproj Includes the new Runtime_124507 regression test source file.
src/tests/JIT/Regression/JitBlue/Runtime_124507/Runtime_124507.cs Adds a reduced repro as an xUnit test entry point for #124507.

egorbot added 2 commits March 3, 2026 13:48
Copilot AI review requested due to automatic review settings March 3, 2026 12:48
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

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

Copilot AI review requested due to automatic review settings March 3, 2026 13:08
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

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

@EgorBo EgorBo marked this pull request as ready for review March 3, 2026 15:04
@EgorBo EgorBo requested a review from AndyAyersMS March 3, 2026 16:08
@EgorBo
Copy link
Member Author

EgorBo commented Mar 3, 2026

PTAL @AndyAyersMS @dotnet/jit-contrib
I tried your suggestion with just checking two bitvectors in the end instead of the second pred walk, but Copilot suggested that it might be more expensive as we PHI don't have too many preds usually, but bitvectors might be long (fgMaxBlocks).

Also, I was not brave enough to just ignore PhiArgs without matching pred blocks (but if I do it, I get -200kb diff improvement).

@AndyAyersMS
Copy link
Member

Can you describe what goes wrong without this fix?

Naively I'd expect that if we considered assertions from preds that no longer reached we would only be more conservative.

Copilot AI review requested due to automatic review settings March 3, 2026 19:02
@EgorBo
Copy link
Member Author

EgorBo commented Mar 3, 2026

@AndyAyersMS it turned out the actual bug was in optGetEdgeAssertions that returned incorrect assertions for an edge that doesn't exist (because of RBO) for that Phi.

I propose we still keep the optVisitReachingAssertions change (it's no longer necessary to fix the bug) since the regression is pretty small just in case. We can alter the PhiVN if we want and remove dead preds somewhere (e.g. in GlobalAP)

egorbot added 2 commits March 3, 2026 21:08
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings March 3, 2026 20:50
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

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

@EgorBo
Copy link
Member Author

EgorBo commented Mar 4, 2026

@AndyAyersMS anything else? Diffs are relatively small (mostly from test collections)

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

I have one more concern but we can address it in a follow up.

For BBJ_COND we're producing two assertion sets, one for true and one for false. It looks like the false assertion set can take advantage of knowing the JTRUE predicate is false, at least in some cases.

Now suppose something in AP modifies flow so that the BBJ_COND becomes BBJ_ALWAYS (by say resolving the JTRUE to be true and removing the false successor edge).

Now we try backwards assertion refinement like we've been increasingly doing. Successors will now look at the "false" bb assertion set from this block, but that might be wrong since it was produced assuming the predicate was false.

Seems like if we change BBJ_COND into BBJ_ALWAYS based on a true predicate, we need overwrite the "if false" assertion set with the "if true" assertion set...?

An alternative is to have the false assertion set represent the set of assertions that are true independent of the JTRUE outcome.

(similar considerations would apply in Morph with local AP, but I don't think we do any backwards refinement there)

@EgorBo
Copy link
Member Author

EgorBo commented Mar 4, 2026

I have one more concern but we can address it in a follow up.

For BBJ_COND we're producing two assertion sets, one for true and one for false. It looks like the false assertion set can take advantage of knowing the JTRUE predicate is false, at least in some cases.

Now suppose something in AP modifies flow so that the BBJ_COND becomes BBJ_ALWAYS (by say resolving the JTRUE to be true and removing the false successor edge).

Now we try backwards assertion refinement like we've been increasingly doing. Successors will now look at the "false" bb assertion set from this block, but that might be wrong since it was produced assuming the predicate was false.

Seems like if we change BBJ_COND into BBJ_ALWAYS based on a true predicate, we need overwrite the "if false" assertion set with the "if true" assertion set...?

An alternative is to have the false assertion set represent the set of assertions that are true independent of the JTRUE outcome.

(similar considerations would apply in Morph with local AP, but I don't think we do any backwards refinement there)

@AndyAyersMS That is a very valid point. In GlobalAP when we use facts and fold comparisons into true/false, we call Morph for them that can convert BBJ_COND into BBJ_ALWAYS (e.g. via fgFoldConditional) and it currently doesn't do anything with what assertion vectors are valid. I can also take a look

@EgorBo
Copy link
Member Author

EgorBo commented Mar 4, 2026

/ba-g deadletter

@EgorBo EgorBo enabled auto-merge (squash) March 4, 2026 19:18
@EgorBo EgorBo merged commit 14c4360 into dotnet:main Mar 4, 2026
133 of 138 checks passed
@EgorBo EgorBo deleted the fix-optVisitReachingAssertions branch March 4, 2026 19:19
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.

JIT: True branch not executed

3 participants