@@ -3199,8 +3199,7 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
3199
3199
}
3200
3200
}
3201
3201
3202
- GenTree* newTree = tree;
3203
- bool propagateType = false ;
3202
+ GenTree* newTree = tree;
3204
3203
3205
3204
// Update 'newTree' with the new value from our table
3206
3205
// Typically newTree == tree and we are updating the node in place
@@ -3217,14 +3216,10 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
3217
3216
3218
3217
case O2K_CONST_INT:
3219
3218
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 ) )
3222
3221
{
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)
3228
3223
{
3229
3224
return nullptr ;
3230
3225
}
@@ -3244,20 +3239,15 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
3244
3239
3245
3240
// Make sure we don't retype const gc handles to TYP_I_IMPL
3246
3241
// 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
- }
3256
3242
3257
- if (propagateType )
3243
+ if (!newTree-> IsIntegralConst ( 0 ) && newTree-> IsIconHandle (GTF_ICON_OBJ_HDL) && !tree-> TypeIs (TYP_REF) )
3258
3244
{
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 ;
3260
3248
}
3249
+
3250
+ newTree->ChangeType (tree->TypeGet ());
3261
3251
}
3262
3252
else
3263
3253
{
0 commit comments