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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3194,8 +3194,7 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
return nullptr;
}

GenTree* newTree = tree;
bool propagateType = false;
GenTree* newTree = tree;

// Update 'newTree' with the new value from our table
// Typically newTree == tree and we are updating the node in place
Expand All @@ -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

if (opts.compReloc && curAssertion->op2.HasIconFlag() && (curAssertion->op2.u1.iconVal != 0))
{
if (curAssertion->op2.GetIconFlag() == GTF_ICON_STATIC_HDL)
{
propagateType = true;
}
else
if (curAssertion->op2.GetIconFlag() != GTF_ICON_STATIC_HDL)
{
return nullptr;
}
Expand All @@ -3239,20 +3234,15 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,

// Make sure we don't retype const gc handles to TYP_I_IMPL
// Although, it's possible for e.g. GTF_ICON_STATIC_HDL
if (!newTree->IsIntegralConst(0) && newTree->IsIconHandle(GTF_ICON_OBJ_HDL))
{
if (tree->TypeIs(TYP_BYREF))
{
// Conservatively don't allow propagation of ICON TYP_REF into BYREF
return nullptr;
}
propagateType = true;
}

if (propagateType)
if (!newTree->IsIntegralConst(0) && newTree->IsIconHandle(GTF_ICON_OBJ_HDL) && !tree->TypeIs(TYP_REF))
{
newTree->ChangeType(tree->TypeGet());
// If the tree is not a TYP_REF, we should not propagate an ICON TYP_REF
// into it, as it may lead to incorrect code generation.
return nullptr;
}

newTree->ChangeType(tree->TypeGet());
}
else
{
Expand Down
Loading