Skip to content

Commit ad4e636

Browse files
authored
JIT: retype more ints during constant prop (#116759)
In particular be willing to retype constant static field handles as TYP_BYREF. Closes #116655.
1 parent ac1e1b9 commit ad4e636

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/coreclr/jit/assertionprop.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,8 +3199,7 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
31993199
}
32003200
}
32013201

3202-
GenTree* newTree = tree;
3203-
bool propagateType = false;
3202+
GenTree* newTree = tree;
32043203

32053204
// Update 'newTree' with the new value from our table
32063205
// Typically newTree == tree and we are updating the node in place
@@ -3217,14 +3216,10 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
32173216

32183217
case O2K_CONST_INT:
32193218

3220-
// Don't propagate handles if we need to report relocs.
3221-
if (opts.compReloc && curAssertion->op2.HasIconFlag() && curAssertion->op2.u1.iconVal != 0)
3219+
// Don't propagate non-nulll non-static handles if we need to report relocs.
3220+
if (opts.compReloc && curAssertion->op2.HasIconFlag() && (curAssertion->op2.u1.iconVal != 0))
32223221
{
3223-
if (curAssertion->op2.GetIconFlag() == GTF_ICON_STATIC_HDL)
3224-
{
3225-
propagateType = true;
3226-
}
3227-
else
3222+
if (curAssertion->op2.GetIconFlag() != GTF_ICON_STATIC_HDL)
32283223
{
32293224
return nullptr;
32303225
}
@@ -3244,20 +3239,15 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
32443239

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

3257-
if (propagateType)
3243+
if (!newTree->IsIntegralConst(0) && newTree->IsIconHandle(GTF_ICON_OBJ_HDL) && !tree->TypeIs(TYP_REF))
32583244
{
3259-
newTree->ChangeType(tree->TypeGet());
3245+
// If the tree is not a TYP_REF, we should not propagate an ICON TYP_REF
3246+
// into it, as it may lead to incorrect code generation.
3247+
return nullptr;
32603248
}
3249+
3250+
newTree->ChangeType(tree->TypeGet());
32613251
}
32623252
else
32633253
{

0 commit comments

Comments
 (0)