Skip to content

Commit

Permalink
Don't propagate const TYP_REF as TYP_I_IMPL (#75661)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Sep 17, 2022
1 parent b55692c commit 58f5c95
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3420,6 +3420,18 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
// Here we have to allocate a new 'large' node to replace the old one
newTree = gtNewIconHandleNode(curAssertion->op2.u1.iconVal,
curAssertion->op2.u1.iconFlags & GTF_ICON_HDL_MASK);

// 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_STR_HDL))
{
if (tree->TypeIs(TYP_BYREF))
{
// Conservatively don't allow propagation of ICON TYP_REF into BYREF
return nullptr;
}
newTree->ChangeType(tree->TypeGet());
}
}
else
{
Expand Down
11 changes: 9 additions & 2 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11121,8 +11121,15 @@ void Compiler::gtDispConst(GenTree* tree)

if (tree->TypeGet() == TYP_REF)
{
assert(tree->AsIntCon()->gtIconVal == 0);
printf(" null");
if (tree->AsIntCon()->gtIconVal == 0)
{
printf(" null");
}
else
{
assert(doesMethodHaveFrozenString());
printf(" 0x%llx", dspIconVal);
}
}
else if ((tree->AsIntCon()->gtIconVal > -1000) && (tree->AsIntCon()->gtIconVal < 1000))
{
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/optcse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ unsigned Compiler::optValnumCSE_Index(GenTree* tree, Statement* stmt)
assert(vnStore->IsVNConstant(vnLibNorm));

// We don't share small offset constants when they require a reloc
// Also, we don't share non-null const gc handles
//
if (!tree->AsIntConCommon()->ImmedValNeedsReloc(this))
if (!tree->AsIntConCommon()->ImmedValNeedsReloc(this) && ((tree->IsIntegralConst(0)) || !varTypeIsGC(tree)))
{
// Here we make constants that have the same upper bits use the same key
//
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8162,7 +8162,7 @@ void Compiler::fgValueNumberTreeConst(GenTree* tree)
}
else
{
assert(tree->IsIconHandle(GTF_ICON_STR_HDL)); // Constant object can be only frozen string.
assert(doesMethodHaveFrozenString()); // Constant object can be only frozen string.
tree->gtVNPair.SetBoth(
vnStore->VNForHandle(ssize_t(tree->AsIntConCommon()->IconValue()), tree->GetIconHandleFlag()));
}
Expand Down

0 comments on commit 58f5c95

Please sign in to comment.