Skip to content

Fix optAssertionProp_Update for IND of handle constant replacement #100422

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

Closed
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
19 changes: 19 additions & 0 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5428,6 +5428,25 @@ GenTree* Compiler::optAssertionProp_Update(GenTree* newTree, GenTree* tree, Stat
if (parent != nullptr)
{
parent->ReplaceOperand(useEdge, newTree);

// If the parent is a GT_IND and we replaced the child with a handle constant, we might need
// to mark the GT_IND as invariant. This is the same as what gtNewIndOfIconHandleNode() does.
// Review: should some kind of more general morphing take care of this?
// Should this share code with gtNewIndOfIconHandleNode()?

if (parent->OperIs(GT_IND) && newTree->IsIconHandle())
{
GenTreeFlags iconFlags = newTree->GetIconHandleFlag();
if (GenTree::HandleKindDataIsInvariant(iconFlags))
{
parent->gtFlags |= GTF_IND_INVARIANT;
if (iconFlags == GTF_ICON_STR_HDL)
{
// String literals are never null
parent->gtFlags |= GTF_IND_NONNULL;
}
}
}
}
else
{
Expand Down