Skip to content

Add budget check to optReachable - #118787

Merged
EgorBo merged 14 commits into
dotnet:mainfrom
EgorBo:opt-repeat-fix
Sep 4, 2025
Merged

EgorBo merged 14 commits into
dotnet:mainfrom
EgorBo:opt-repeat-fix

Conversation

@EgorBo

@EgorBo EgorBo commented Aug 15, 2025

Copy link
Copy Markdown
Member

Fixes #106675

Reduces crossgen compilation time from 60s to 6s for that test.

@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 Aug 15, 2025
@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.

Comment thread src/coreclr/jit/ifconversion.cpp Resolved
@EgorBo
EgorBo marked this pull request as ready for review August 18, 2025 13:11
Copilot AI review requested due to automatic review settings August 18, 2025 13:11
@EgorBo

EgorBo commented Aug 18, 2025

Copy link
Copy Markdown
Member Author

PTAL @jakobbotsch @dotnet/jit-contrib

A few diffs, only from the fast-path check (m_comp->compHasBackwardJump && - I inspected the diffs, they don't contain any loops, but something introduces an artificial backward branch, most likely it's tail-deduplication phase.

@EgorBo
EgorBo requested a review from jakobbotsch August 18, 2025 13:12
Comment thread src/coreclr/jit/redundantbranchopts.cpp Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses a performance issue in the JIT compiler's if-conversion optimization by adding budget checks to prevent excessive computation during reachability analysis. The change reduces crossgen compilation time from 60 seconds to 6 seconds for the reported test case.

Key changes:

  • Added a budget parameter to optReachable to limit the number of blocks examined during reachability analysis
  • Modified if-conversion logic to use the budget and skip expensive checks when appropriate
  • Optimized debug checking routines to avoid expensive operations on large basic block counts

Reviewed Changes

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

File Description
src/coreclr/jit/compiler.h Added optional budget parameter to optReachable method signature
src/coreclr/jit/redundantbranchopts.cpp Implemented budget checking logic in optReachable with two code paths for budgeted vs non-budgeted operation
src/coreclr/jit/ifconversion.cpp Added reachability budget field and logic to use budgeted reachability checks only when backward jumps are present
src/coreclr/jit/fgdiagnostic.cpp Optimized debug checks to skip expensive operations when basic block count exceeds 10,000

Comment thread src/coreclr/jit/redundantbranchopts.cpp Resolved
Comment thread src/coreclr/jit/redundantbranchopts.cpp Resolved
Comment thread src/coreclr/jit/ifconversion.cpp Resolved
Comment thread src/coreclr/jit/ifconversion.cpp Resolved
@risc-vv

risc-vv commented Aug 18, 2025

Copy link
Copy Markdown

@dotnet/samsung Could you please take a look? These changes may be related to riscv64.

@EgorBo

EgorBo commented Aug 18, 2025

Copy link
Copy Markdown
Member Author

@dotnet/samsung Could you please take a look? These changes may be related to riscv64.

Presumably not related.

Comment thread src/coreclr/jit/ifconversion.cpp Resolved
Comment thread src/coreclr/jit/ifconversion.cpp Resolved
@kg

kg commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

Do you know whether this also reduces peak memory usage during compilation? I can't tell if the allocation of all the huge bitvecs is suppressed by the budget system or not. Improved compile time is good but my understanding is that the test failure in #106675 is caused by the oom killer, so being faster won't necessarily fix it even if it is fantastic for it to be faster.

@EgorBo

EgorBo commented Sep 2, 2025

Copy link
Copy Markdown
Member Author

Do you know whether this also reduces peak memory usage during compilation?

Hm.. no, that is something else (I'm seeing 2GB peak memory usage while compiling the repro), this PR only fixes the compilation duration issue, the phase that I'm touching here is not responsible for the working set size.

@EgorBo
EgorBo requested a review from jakobbotsch September 2, 2025 12:36
@EgorBo

EgorBo commented Sep 4, 2025

Copy link
Copy Markdown
Member Author

ping @jakobbotsch

@EgorBo
EgorBo enabled auto-merge (squash) September 4, 2025 10:12
@EgorBo
EgorBo merged commit d2a3735 into dotnet:main Sep 4, 2025
@EgorBo
EgorBo deleted the opt-repeat-fix branch September 4, 2025 10:12
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

Test failure: JIT/Regression/JitBlue/DevDiv_255294/DevDiv_255294/DevDiv_255294.cmd

5 participants