Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Aug 15, 2025

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
Copy link
Contributor

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

@EgorBo EgorBo marked this pull request as ready for review August 18, 2025 13:11
@Copilot Copilot AI review requested due to automatic review settings August 18, 2025 13:11
@EgorBo
Copy link
Member Author

EgorBo commented Aug 18, 2025

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
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 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

@risc-vv
Copy link

risc-vv commented Aug 18, 2025

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

@EgorBo
Copy link
Member Author

EgorBo commented Aug 18, 2025

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

Presumably not related.

@kg
Copy link
Member

kg commented Aug 21, 2025

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
Copy link
Member Author

EgorBo commented Sep 2, 2025

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
Copy link
Member Author

EgorBo commented Sep 4, 2025

ping @jakobbotsch

@EgorBo EgorBo enabled auto-merge (squash) September 4, 2025 10:12
@EgorBo EgorBo merged commit d2a3735 into dotnet:main Sep 4, 2025
112 checks passed
@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

4 participants