Skip to content

JIT: Keep side effects in promotion decomposition #115221

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
May 1, 2025

Conversation

jakobbotsch
Copy link
Member

If the source is a load from an arbitrary address and the destination is a local that is unused then it may be that we end up creating no loads at all. In that case we should still keep the side effects of the address computation.

Fix #114571

If the source is a load from an arbitrary address and the destination is
a local that is unused then it may be that we end up creating no loads
at all. In that case we should still keep the side effects of the
address computation.
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 1, 2025
Copy link
Contributor

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

@jakobbotsch jakobbotsch marked this pull request as ready for review May 1, 2025 14:21
@Copilot Copilot AI review requested due to automatic review settings May 1, 2025 14:21
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @kunalspathak

No diffs

@jakobbotsch jakobbotsch requested a review from kunalspathak May 1, 2025 14:22
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 issue #114571 by ensuring that side effects from address computations are preserved even when the resultant load is unused.

  • Adds a regression test in Runtime_114571.cs to trigger a NullReferenceException due to a null array access.
  • Modifies the JIT promotion decomposition logic in promotiondecomposition.cpp to extract and keep side effects when there are zero uses of the address.

Reviewed Changes

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

File Description
src/tests/JIT/Regression/JitBlue/Runtime_114571/Runtime_114571.cs Introduces a regression test that intentionally causes a NullReferenceException to verify behavior.
src/coreclr/jit/promotiondecomposition.cpp Alters the condition to extract side effects when numAddrUses is 0, ensuring side effects are maintained.
Files not reviewed (1)
  • src/tests/JIT/Regression/JitBlue/Runtime_114571/Runtime_114571.csproj: Language not supported

@@ -588,7 +588,17 @@ class DecompositionPlan
numAddrUses++;
}

Copy link
Preview

Copilot AI May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a comment explaining why side effects are extracted when numAddrUses equals 0 to clarify that this branch preserves the side effects of the address computation for unused loads.

Suggested change
// If the address is not used (numAddrUses == 0), we still need to preserve
// any side effects from the address computation. Extract these side effects
// and add them to the statement list to ensure they are not lost.

Copilot uses AI. Check for mistakes.

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jakobbotsch jakobbotsch merged commit 5d2444b into dotnet:main May 1, 2025
113 of 115 checks passed
@jakobbotsch jakobbotsch deleted the fix-114571 branch May 1, 2025 16:37
@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 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.

JIT: Debug: Throws 'System.NullReferenceException', Release: Runs successfully
2 participants