Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f4b39a2

Browse files
committed
Incorporate review feedback
Removed legacy special-casing, verified legacy path works fine with the intrinsics and opts fully enabled.
1 parent 9b20ecd commit f4b39a2

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

src/jit/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5010,7 +5010,7 @@ class Compiler
50105010
TPK_Other = 4 // RuntimeType via other means
50115011
};
50125012

5013-
TypeProducerKind gtCanOptimizeTypeEquality(GenTreePtr tree);
5013+
TypeProducerKind gtGetTypeProducerKind(GenTree* tree);
50145014
bool gtIsTypeHandleToRuntimeTypeHelper(GenTreeCall* call);
50155015
bool gtIsActiveCSE_Candidate(GenTreePtr tree);
50165016

src/jit/gentree.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12189,7 +12189,7 @@ GenTree* Compiler::gtFoldTypeEqualityCall(CorInfoIntrinsics methodID, GenTree* o
1218912189
// The method must be be a type equality intrinsic
1219012190
assert(methodID == CORINFO_INTRINSIC_TypeEQ || methodID == CORINFO_INTRINSIC_TypeNEQ);
1219112191

12192-
if ((gtCanOptimizeTypeEquality(op1) == TPK_Unknown) && (gtCanOptimizeTypeEquality(op2) == TPK_Unknown))
12192+
if ((gtGetTypeProducerKind(op1) == TPK_Unknown) && (gtGetTypeProducerKind(op2) == TPK_Unknown))
1219312193
{
1219412194
return nullptr;
1219512195
}
@@ -12306,23 +12306,23 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree)
1230612306

1230712307
// Screen for the right kinds of operands
1230812308
GenTree* const op1 = tree->gtOp.gtOp1;
12309-
const TypeProducerKind op1Kind = gtCanOptimizeTypeEquality(op1);
12309+
const TypeProducerKind op1Kind = gtGetTypeProducerKind(op1);
1231012310
if (op1Kind == TPK_Unknown)
1231112311
{
1231212312
return tree;
1231312313
}
1231412314

1231512315
GenTree* const op2 = tree->gtOp.gtOp2;
12316-
const TypeProducerKind op2Kind = gtCanOptimizeTypeEquality(op2);
12316+
const TypeProducerKind op2Kind = gtGetTypeProducerKind(op2);
1231712317
if (op2Kind == TPK_Unknown)
1231812318
{
1231912319
return tree;
1232012320
}
1232112321

1232212322
// We must have a handle on one side or the other here to optimize,
1232312323
// otherwise we can't be sure that optimizing is sound.
12324-
const bool op1IsFromHandle = op1Kind == TPK_Handle;
12325-
const bool op2IsFromHandle = op2Kind == TPK_Handle;
12324+
const bool op1IsFromHandle = (op1Kind == TPK_Handle);
12325+
const bool op2IsFromHandle = (op2Kind == TPK_Handle);
1232612326

1232712327
if (!(op1IsFromHandle || op2IsFromHandle))
1232812328
{
@@ -12432,13 +12432,8 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree)
1243212432
// opHandleArgument is the method table we're looking for.
1243312433
GenTree* const knownMT = opHandleArgument;
1243412434

12435-
#ifdef LEGACY_BACKEND
12436-
// Fetch object method table from the object itself
12437-
GenTree* const objMT = gtNewOperNode(GT_IND, TYP_I_IMPL, opOther->gtCall.gtCallObjp);
12438-
#else
1243912435
// Fetch object method table from the object itself
1244012436
GenTree* const objMT = gtNewOperNode(GT_IND, TYP_I_IMPL, opOther->gtUnOp.gtOp1);
12441-
#endif
1244212437

1244312438
// Update various flags
1244412439
objMT->gtFlags |= GTF_EXCEPT;
@@ -15416,8 +15411,8 @@ void Compiler::gtCheckQuirkAddrExposedLclVar(GenTreePtr tree, GenTreeStack* pare
1541615411
}
1541715412

1541815413
//------------------------------------------------------------------------
15419-
// gtCanOptimizeTypeEquality: check if tree is a suitable input for type
15420-
// equality optimization
15414+
// gtGetTypeProducerKind: determine if a tree produces a runtime type, and
15415+
// if so, how.
1542115416
//
1542215417
// Arguments:
1542315418
// tree - tree to examine
@@ -15443,7 +15438,7 @@ void Compiler::gtCheckQuirkAddrExposedLclVar(GenTreePtr tree, GenTreeStack* pare
1544315438
//
1544415439
// into a method call.
1544515440

15446-
Compiler::TypeProducerKind Compiler::gtCanOptimizeTypeEquality(GenTree* tree)
15441+
Compiler::TypeProducerKind Compiler::gtGetTypeProducerKind(GenTree* tree)
1544715442
{
1544815443
if (tree->gtOper == GT_CALL)
1544915444
{

src/jit/importer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,7 +3522,6 @@ GenTreePtr Compiler::impIntrinsic(GenTreePtr newobjThis,
35223522
// Call the regular function.
35233523
break;
35243524

3525-
#ifndef LEGACY_BACKEND
35263525
case CORINFO_INTRINSIC_Object_GetType:
35273526
{
35283527
op1 = impPopStack().val;
@@ -3532,9 +3531,7 @@ GenTreePtr Compiler::impIntrinsic(GenTreePtr newobjThis,
35323531
{
35333532
if (op1->IsBoxedValue())
35343533
{
3535-
#ifdef DEBUG
35363534
JITDUMP("Attempting to optimize box(...).getType() to direct type construction\n");
3537-
#endif
35383535

35393536
// Try and clean up the box. Obtain the handle we
35403537
// were going to pass to the newobj.
@@ -3576,7 +3573,7 @@ GenTreePtr Compiler::impIntrinsic(GenTreePtr newobjThis,
35763573
}
35773574
break;
35783575
}
3579-
#endif
3576+
35803577
// Implement ByReference Ctor. This wraps the assignment of the ref into a byref-like field
35813578
// in a value type. The canonical example of this is Span<T>. In effect this is just a
35823579
// substitution. The parameter byref will be assigned into the newly allocated object.

src/jit/morph.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11964,16 +11964,16 @@ GenTreePtr Compiler::fgMorphSmpOp(GenTreePtr tree, MorphAddrContext* mac)
1196411964
}
1196511965
break;
1196611966

11967-
case GT_EQ:
11968-
case GT_NE:
11969-
{
11970-
GenTree* optimizedTree = gtFoldTypeCompare(tree);
11967+
case GT_EQ:
11968+
case GT_NE:
11969+
{
11970+
GenTree* optimizedTree = gtFoldTypeCompare(tree);
1197111971

11972-
if (optimizedTree != tree)
11973-
{
11974-
return fgMorphTree(optimizedTree);
11975-
}
11972+
if (optimizedTree != tree)
11973+
{
11974+
return fgMorphTree(optimizedTree);
1197611975
}
11976+
}
1197711977

1197811978
__fallthrough;
1197911979

0 commit comments

Comments
 (0)