Skip to content

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Aug 27, 2025

This reverts commit e0b14e9. That change is not correct as it removes the safe guard that prevents hoisting throwing expressions out of conditionally executed blocks.

Also renames m_beforeSideEffect to m_canHoistSideEffects to capture more precisely what it represents and why the conditionality of the blocks play a role. Also adds a test.

Fix #119061

…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.
Copilot AI review requested due to automatic review settings August 27, 2025 12:03
Copy link
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 reverts a previous change that incorrectly removed a safeguard preventing loop hoisting from conditionally executed blocks. The reverted change (commit e0b14e9) was causing incorrect JIT optimization behavior where expressions with side effects could be hoisted out of conditionally executed code blocks, leading to potential runtime errors.

  • Restores the m_beforeSideEffect = false safeguard in loop hoisting logic
  • Adds comprehensive comments explaining why the safeguard is necessary
  • Includes a regression test to prevent similar issues in the future

Reviewed Changes

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

File Description
src/coreclr/jit/optimizer.cpp Reverts the loop hoisting logic and adds detailed comments explaining the safeguard mechanism
src/tests/JIT/Regression/JitBlue/Runtime_119061/Runtime_119061.cs Adds regression test with conditional block and side-effect operations to verify fix
src/tests/JIT/Regression/JitBlue/Runtime_119061/Runtime_119061.csproj Test project configuration for the regression 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 27, 2025
@dotnet-policy-service
Copy link
Contributor

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

@jakobbotsch jakobbotsch changed the title Revert "JIT: Remove side effect detection quirk in loop hoisting (#118463)" Revert "JIT: Remove side effect detection quirk in loop hoisting (#118463)" with some improvements Aug 28, 2025
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

Note that this isn't a straight up reversion since I noticed another potential issue while looking at this code.

@jakobbotsch
Copy link
Member Author

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17459176149

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.

JIT: Exception thrown only with runtime async

2 participants