Skip to content

JIT: retype more ints during constant prop #116759

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
Jun 19, 2025

Conversation

AndyAyersMS
Copy link
Member

In particular be willing to retype constant static field handles as TYP_BYREF.

Closes #116655.

In particular be willing to retype constant static field handles as TYP_BYREF.

Closes dotnet#116655.
@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 17:51
@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 Jun 17, 2025
Copy link
Contributor

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

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 refines constant propagation for integer constants by allowing static field handles and certain object handles to be retyped to reference types under more conditions, removing the old propagateType flag.

  • Simplified relocation checks to permit only non-zero static handles with compReloc enabled.
  • Updated object-handle propagation to reject non-TYP_REF trees and always apply ChangeType.
  • Removed the propagateType flag and hoisted the ChangeType call outside conditionals.
Comments suppressed due to low confidence (2)

src/coreclr/jit/assertionprop.cpp:3238

  • This new branch rejects object handles when the tree isn't TYP_REF; consider adding a unit test to cover both accepting and rejecting paths for GTF_ICON_OBJ_HDL under different tree types.
                if (!newTree->IsIntegralConst(0) && newTree->IsIconHandle(GTF_ICON_OBJ_HDL) && !tree->TypeIs(TYP_REF))

src/coreclr/jit/assertionprop.cpp:3245

  • The ChangeType call is now unconditional for all O2K_CONST_INT cases, but originally it only applied when propagateType was true. Consider reinstating a guard so that only intended handle constants actually get retyped.
                newTree->ChangeType(tree->TypeGet());

@@ -3212,14 +3211,10 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,

case O2K_CONST_INT:

// Don't propagate handles if we need to report relocs.
if (opts.compReloc && curAssertion->op2.HasIconFlag() && curAssertion->op2.u1.iconVal != 0)
// Don't propagate non-nulll non-static handles if we need to report relocs.
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

There's a typo in the comment: change "non-nulll" to "non-null".

Suggested change
// Don't propagate non-nulll non-static handles if we need to report relocs.
// Don't propagate non-null non-static handles if we need to report relocs.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix this in a subsequent PR

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib PTAL

Some diffs, mainly around different CSE patterns for constants. Possibly we should make CSE of constant handles more type blind and conform to uses or something.

Copy link
Member

@amanasifkhalid amanasifkhalid left a comment

Choose a reason for hiding this comment

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

LGTM

@AndyAyersMS AndyAyersMS merged commit ad4e636 into dotnet:main Jun 19, 2025
108 of 110 checks passed
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.

Assertion failed 'genActualType(op1) == genActualType(op2)' in 'System.SpanTests.SpanTests:AsciiNeedle_ProperlyHandlesEdgeCases_Byte(bool)
2 participants