Skip to content

ignore unreachable preds in optVisitReachingAssertions#127307

Merged
EgorBo merged 2 commits intodotnet:mainfrom
EgorBo:fast-isUnreachableBlock
Apr 23, 2026
Merged

ignore unreachable preds in optVisitReachingAssertions#127307
EgorBo merged 2 commits intodotnet:mainfrom
EgorBo:fast-isUnreachableBlock

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented Apr 23, 2026

…h fast unreachable-block check

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 23, 2026 00:28
@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 Apr 23, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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 updates optVisitReachingAssertions to tolerate SSA PHI arguments that originate from blocks that are no longer reachable, avoiding conservative early-aborts in those cases.

Changes:

  • Adds a local helper to classify predecessor blocks as unreachable based on missing normal predecessors (with EH handler/filter entry exceptions).
  • Skips visiting PHI args coming from such unreachable blocks and logs via JITDUMP.
  • Marks skipped blocks as visited so the later “phi-preds cover block preds” check doesn’t fail spuriously.

@AndyAyersMS
Copy link
Copy Markdown
Member

We could / should do likewise in the assertion prop data flow computations in AssertionPropFlowCallback::Merge

Comment thread src/coreclr/jit/compiler.hpp
@jakobbotsch
Copy link
Copy Markdown
Member

We could / should do likewise in the assertion prop data flow computations in AssertionPropFlowCallback::Merge

I wonder if we can remove unreachable blocks after RBO instead, though who knows how downstream phases will cope with that given the SSA state. Maybe repairing SSA if blocks are removed wouldn't be that hard, though.

@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented Apr 23, 2026

@jakobbotsch @AndyAyersMS
So I've applied both of your suggestions and it had almost no impact on overall diffs: -38,755 total diffs on win-x64 with this PR, your suggesions (to also check DFS and ignore unreachable preds during forward analysis): -38,799.

I checked a few diffs and it turned out that such blocks become unreachable during global assertion prop itself (when we fold something and then call fgMorphStatements), so it is expected why both of the suggestions do not help.

Example dump https://gist.githubusercontent.com/EgorBo/40a1238e362fbc0e47a3381e0ab32c7c/raw/d028badf544677688cafc964b9c05ecab1eb86d3/dump.txt (see is unreachable, ignoring). in this case it's BB28 block.

So I suggest to leave as is for simplicity?

@BoyBaykiller
Copy link
Copy Markdown
Contributor

With this change does the increment get constant folded into STORE(4) after AP?

int Unoptimized(int a, int b)
{
    int num = 0;

    if (a == b)
    {
        num += 3;
    }
    if (a == b)
    {
        num++;
    }
    
    return num;
}

@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented Apr 23, 2026

With this change does the increment get constant folded into STORE(4) after AP?

int Unoptimized(int a, int b)
{
    int num = 0;

    if (a == b)
    {
        num += 3;
    }
    if (a == b)
    {
        num++;
    }
    
    return num;
}

doesn't look so

@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented Apr 23, 2026

/ba-g timeouts

@EgorBo EgorBo merged commit fbb7705 into dotnet:main Apr 23, 2026
121 of 135 checks passed
@EgorBo EgorBo deleted the fast-isUnreachableBlock branch April 23, 2026 18:46
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.

6 participants