Skip to content

JIT: Consider conditionally executed loop statements for hoisting #117829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025

Conversation

amanasifkhalid
Copy link
Member

Fixes the roughly 10x regression in #116486. This quirks loop hoisting to iterate all loop blocks, and consider hoisting expensive statements even if they don't execute every iteration. The (IND_COST_EX * 16) cutoff was chosen to minimize churn, while still solving the above regression.

@Copilot Copilot AI review requested due to automatic review settings July 18, 2025 18:07
@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 Jul 18, 2025
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 optimizes the JIT loop hoisting algorithm to address a significant performance regression by considering conditionally executed loop statements for hoisting. The change switches from processing only definitely executed blocks to evaluating all loop blocks and applying cost-based heuristics for hoisting expensive statements from conditionally executed blocks.

Key changes:

  • Modified loop hoisting to iterate through all loop blocks rather than just definitely executed ones
  • Added cost-based filtering for conditionally executed statements using an (IND_COST_EX * 16) threshold
  • Changed data structures from ArrayStack to BitVec for tracking definitely executed blocks

Reviewed Changes

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

File Description
src/coreclr/jit/optimizer.cpp Main implementation changes for loop hoisting algorithm including data structure changes and cost-based heuristics
src/coreclr/jit/compiler.h Updated method signatures to support new BitVec-based approach and defExecuted parameter
Comments suppressed due to low confidence (1)

Copy link
Contributor

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

@amanasifkhalid
Copy link
Member Author

Diffs are small locally:

FullOpts (-278 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
benchmarks.run.windows.x64.checked.mch 8,865,007 -300 -5.00%
benchmarks.run_pgo.windows.x64.checked.mch 54,648,047 -4 -0.00%
benchmarks.run_pgo_optrepeat.windows.x64.checked.mch 8,867,064 -300 -5.00%
coreclr_tests.run.windows.x64.checked.mch 135,728,409 -295 -3.25%
libraries.crossgen2.windows.x64.checked.mch 38,310,108 +0 0.00%
libraries_tests.run.windows.x64.Release.mch 143,426,557 +782 -0.06%
libraries_tests_no_tiered_compilation.run.windows.x64.Release.mch 143,316,941 -114 -2.52%
realworld.run.windows.x64.checked.mch 11,583,751 -47 -2.47%

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.

LGTM. Feel free to address my comments later if you like.

@amanasifkhalid
Copy link
Member Author

Diffs are small, though the TP cost is high for such a focused change. I think we were going to incur this cost at some point in the near future once we started to consider all loop blocks for hoisting. Plus, #117423 and #117743 pay for most of this.

@amanasifkhalid amanasifkhalid enabled auto-merge (squash) July 18, 2025 20:41
@amanasifkhalid amanasifkhalid merged commit 2fe0457 into dotnet:main Jul 18, 2025
109 of 111 checks passed
@amanasifkhalid amanasifkhalid deleted the loop-hoisting-quirk branch July 18, 2025 21:21
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.

2 participants