Skip to content

Commit eec5790

Browse files
authored
Fix missing side-effects handling in gtFoldTypeCompare (#121875)
Fixes #121874
1 parent dc366eb commit eec5790

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/coreclr/jit/gentree.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14266,18 +14266,6 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree)
1426614266
return tree;
1426714267
}
1426814268

14269-
// Check if an object of this type can even exist
14270-
if (info.compCompHnd->getExactClasses(clsHnd, 0, nullptr) == 0)
14271-
{
14272-
JITDUMP("Runtime reported %p (%s) is never allocated\n", dspPtr(clsHnd), eeGetClassName(clsHnd));
14273-
14274-
const bool operatorIsEQ = (oper == GT_EQ);
14275-
const int compareResult = operatorIsEQ ? 0 : 1;
14276-
JITDUMP("Runtime reports comparison is known at jit time: %u\n", compareResult);
14277-
GenTree* result = gtNewIconNode(compareResult);
14278-
return result;
14279-
}
14280-
1428114269
// We're good to go.
1428214270
JITDUMP("Optimizing compare of obj.GetType()"
1428314271
" and type-from-handle to compare method table pointer\n");
@@ -14298,6 +14286,20 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree)
1429814286
objOp = opOther->AsCall()->gtArgs.GetThisArg()->GetNode();
1429914287
}
1430014288

14289+
// Check if an object of this type can even exist
14290+
if (info.compCompHnd->getExactClasses(clsHnd, 0, nullptr) == 0)
14291+
{
14292+
JITDUMP("Runtime reported %p (%s) is never allocated\n", dspPtr(clsHnd), eeGetClassName(clsHnd));
14293+
14294+
const bool operatorIsEQ = (oper == GT_EQ);
14295+
const int compareResult = operatorIsEQ ? 0 : 1;
14296+
JITDUMP("Runtime reports comparison is known at jit time: %u\n", compareResult);
14297+
14298+
GenTree* result = gtNewIconNode(compareResult);
14299+
GenTree* sideEffects = fgAddrCouldBeNull(objOp) ? gtNewNullCheck(objOp) : objOp;
14300+
return gtWrapWithSideEffects(result, sideEffects, GTF_ALL_EFFECT);
14301+
}
14302+
1430114303
bool isExact = false;
1430214304
bool isNonNull = false;
1430314305
CORINFO_CLASS_HANDLE objCls = gtGetClassHandle(objOp, &isExact, &isNonNull);

0 commit comments

Comments
 (0)