Skip to content

JIT: Remove side effect detection quirk in loop hoisting - #118463

Merged
amanasifkhalid merged 3 commits into
dotnet:mainfrom
amanasifkhalid:hoisting-side-effect-check
Aug 12, 2025
Merged

amanasifkhalid merged 3 commits into
dotnet:mainfrom
amanasifkhalid:hoisting-side-effect-check

Conversation

@amanasifkhalid

@amanasifkhalid amanasifkhalid commented Aug 6, 2025 •

Copy link
Copy Markdown
Contributor

Addresses some of the regressions in #116486 and #116754. Hoisting's traversal of the loop body was previously not sensitive to execution flow, so it was overly conservative in its side effect detection, operating under the assumption that every block after the loop header could execute after the first global side effect. Now that hoisting visits every loop block in RPO, we can remove this assumption.

Copilot AI review requested due to automatic review settings August 6, 2025 20:55
@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 6, 2025

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 improves side effect detection during loop hoisting by making the traversal more flow-sensitive. Previously, the JIT was overly conservative, assuming every block after the loop header could execute after the first global side effect. The new approach propagates side effect state through the control flow paths of the loop, enabling more precise hoisting decisions.

Key changes:

  • Replaced global m_beforeSideEffect flag with per-block side effect tracking using m_sideEffectBlocks BitVec
  • Modified side effect detection to propagate through control flow rather than assuming worst-case after first block
  • Updated comments to reflect the new flow-sensitive approach

Comment thread src/coreclr/jit/optimizer.cpp Resolved
Comment thread src/coreclr/jit/optimizer.cpp Resolved
@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.

@amanasifkhalid amanasifkhalid changed the title JIT: Improve side effect detection in loop hoisting JIT: Remove side effect detection quirk in loop hoisting Aug 11, 2025
@amanasifkhalid

Copy link
Copy Markdown
Contributor Author

cc @dotnet/jit-contrib, @AndyAyersMS PTAL. I previously tried a more sophisticated approach for propagating side effect state more precisely through conditional paths, but this seemed to overwhelm CSE with candidates, leading to about a 50/50 split of large PerfScore improvements and regressions. To make that approach work, I'll probably have to further quirk the JIT to only hoist newly valid candidates if they're sufficiently expensive. For now, this change yields small but largely positive diffs.

@amanasifkhalid

Copy link
Copy Markdown
Contributor Author

ping @AndyAyersMS

@amanasifkhalid
amanasifkhalid merged commit e0b14e9 into dotnet:main Aug 12, 2025
@amanasifkhalid
amanasifkhalid deleted the hoisting-side-effect-check branch August 12, 2025 15:12
jakobbotsch added a commit to jakobbotsch/runtime that referenced this pull request Aug 27, 2025
…net#118463)"

This reverts commit e0b14e9. That
change is not correct as it removes the safe guard that prevents
hoisting out of conditionally executed blocks.
jakobbotsch added a commit that referenced this pull request Aug 29, 2025
…8463)" with some improvements (#119138)

This reverts commit e0b14e9. That
change is not correct as it removes the safe guard that prevents
hoisting out of conditionally executed blocks.
github-actions Bot pushed a commit that referenced this pull request Sep 4, 2025
…8463)"

This reverts commit e0b14e9. That
change is not correct as it removes the safe guard that prevents
hoisting out of conditionally executed blocks.
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 12, 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.

3 participants