Skip to content
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

[RyuJIT] static readonly fields can be Invariant #44562

Merged
merged 9 commits into from
Mar 2, 2021
9 changes: 9 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6490,6 +6490,15 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac)
tree->SetOper(GT_IND);
tree->AsOp()->gtOp1 = addr;

bool plsSpeculative = true;
if ((info.compCompHnd->getStaticFieldCurrentClass(symHnd, &plsSpeculative) != NO_CLASS_HANDLE) &&
!plsSpeculative)
{
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
JITDUMP("Marking static read-only field '%s' as invariant.\n", eeGetFieldName(symHnd));
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
tree->gtFlags |= GTF_IND_INVARIANT;
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
addr->gtFlags = GTF_ICON_CONST_PTR;
}

return fgMorphSmpOp(tree);
}
else
Expand Down