Skip to content

Commit d5a77e6

Browse files
Revert "JIT: revise how we track if nodes have been morphed (#110787)"
This reverts commit 4822cc0.
1 parent cf4d2b0 commit d5a77e6

File tree

7 files changed

+222
-293
lines changed

7 files changed

+222
-293
lines changed

src/coreclr/jit/compiler.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5438,10 +5438,6 @@ class Compiler
54385438
void fgMorphBlock(BasicBlock* block, MorphUnreachableInfo* unreachableInfo = nullptr);
54395439
void fgMorphStmts(BasicBlock* block);
54405440

5441-
#ifdef DEBUG
5442-
void fgPostGlobalMorphChecks();
5443-
#endif
5444-
54455441
void fgMergeBlockReturn(BasicBlock* block);
54465442

54475443
bool fgMorphBlockStmt(BasicBlock* block, Statement* stmt DEBUGARG(const char* msg), bool invalidateDFSTreeOnFGChange = true);
@@ -6789,7 +6785,7 @@ class Compiler
67896785
void fgKillDependentAssertionsSingle(unsigned lclNum DEBUGARG(GenTree* tree));
67906786
void fgKillDependentAssertions(unsigned lclNum DEBUGARG(GenTree* tree));
67916787
void fgMorphTreeDone(GenTree* tree);
6792-
void fgMorphTreeDone(GenTree* tree, bool optAssertionPropDone DEBUGARG(int morphNum = 0));
6788+
void fgMorphTreeDone(GenTree* tree, bool optAssertionPropDone, bool isMorphedTree DEBUGARG(int morphNum = 0));
67936789

67946790
Statement* fgMorphStmt;
67956791
unsigned fgBigOffsetMorphingTemps[TYP_COUNT];

src/coreclr/jit/compiler.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,6 @@ inline GenTree::GenTree(genTreeOps oper, var_types type DEBUGARG(bool largeNode)
13541354
gtLIRFlags = 0;
13551355
#ifdef DEBUG
13561356
gtDebugFlags = GTF_DEBUG_NONE;
1357-
gtMorphCount = 0;
13581357
#endif // DEBUG
13591358
gtCSEnum = NO_CSE;
13601359
ClearAssertion();

src/coreclr/jit/gentree.cpp

Lines changed: 63 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4903,6 +4903,7 @@ static void SetIndirectStoreEvalOrder(Compiler* comp, GenTreeIndir* store, bool*
49034903
* 1. GetCostEx() to the execution complexity estimate
49044904
* 2. GetCostSz() to the code size estimate
49054905
* 3. Sometimes sets GTF_ADDRMODE_NO_CSE on nodes in the tree.
4906+
* 4. DEBUG-only: clears GTF_DEBUG_NODE_MORPHED.
49064907
*/
49074908

49084909
#ifdef _PREFAST_
@@ -14387,7 +14388,10 @@ GenTree* Compiler::gtFoldExprSpecial(GenTree* tree)
1438714388
// Helper function that creates a new IntCon node and morphs it, if required
1438814389
auto NewMorphedIntConNode = [&](int value) -> GenTreeIntCon* {
1438914390
GenTreeIntCon* icon = gtNewIconNode(value);
14390-
icon->SetMorphed(this);
14391+
if (fgGlobalMorph)
14392+
{
14393+
INDEBUG(icon->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
14394+
}
1439114395
return icon;
1439214396
};
1439314397

@@ -14398,14 +14402,18 @@ GenTree* Compiler::gtFoldExprSpecial(GenTree* tree)
1439814402
assert(varTypeIsUnsigned(castToType));
1439914403

1440014404
GenTreeCast* cast = gtNewCastNode(TYP_INT, op1, false, castToType);
14401-
cast->SetMorphed(this);
14402-
fgMorphTreeDone(cast);
14405+
if (fgGlobalMorph)
14406+
{
14407+
fgMorphTreeDone(cast);
14408+
}
1440314409

1440414410
if (type == TYP_LONG)
1440514411
{
1440614412
cast = gtNewCastNode(TYP_LONG, cast, true, TYP_LONG);
14407-
cast->SetMorphed(this);
14408-
fgMorphTreeDone(cast);
14413+
if (fgGlobalMorph)
14414+
{
14415+
fgMorphTreeDone(cast);
14416+
}
1440914417
}
1441014418

1441114419
return cast;
@@ -14672,7 +14680,14 @@ GenTree* Compiler::gtFoldExprSpecial(GenTree* tree)
1467214680
DISPTREE(tree);
1467314681
JITDUMP("Transformed into:\n");
1467414682
DISPTREE(op);
14675-
op->SetMorphed(this);
14683+
14684+
if (fgGlobalMorph)
14685+
{
14686+
// We can sometimes produce a comma over the constant if the original op
14687+
// had a side effect, so just ensure we set the flag (which will be already
14688+
// set for the operands otherwise).
14689+
INDEBUG(op->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
14690+
}
1467614691
return op;
1467714692
}
1467814693

@@ -14727,9 +14742,10 @@ GenTree* Compiler::gtFoldExprSpecialFloating(GenTree* tree)
1472714742
// Helper function that creates a new IntCon node and morphs it, if required
1472814743
auto NewMorphedIntConNode = [&](int value) -> GenTreeIntCon* {
1472914744
GenTreeIntCon* icon = gtNewIconNode(value);
14730-
14731-
icon->SetMorphed(this);
14732-
14745+
if (fgGlobalMorph)
14746+
{
14747+
INDEBUG(icon->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
14748+
}
1473314749
return icon;
1473414750
};
1473514751

@@ -14891,8 +14907,14 @@ GenTree* Compiler::gtFoldExprSpecialFloating(GenTree* tree)
1489114907
DISPTREE(tree);
1489214908
JITDUMP("Transformed into:\n");
1489314909
DISPTREE(op);
14894-
op->SetMorphed(this);
1489514910

14911+
if (fgGlobalMorph)
14912+
{
14913+
// We can sometimes produce a comma over the constant if the original op
14914+
// had a side effect, so just ensure we set the flag (which will be already
14915+
// set for the operands otherwise).
14916+
INDEBUG(op->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
14917+
}
1489614918
return op;
1489714919
}
1489814920

@@ -15413,11 +15435,6 @@ GenTree* Compiler::gtOptimizeEnumHasFlag(GenTree* thisOp, GenTree* flagOp)
1541315435
Statement* thisStoreStmt = thisOp->AsBox()->gtCopyStmtWhenInlinedBoxValue;
1541415436
thisStoreStmt->SetRootNode(thisStore);
1541515437
thisValOpt = gtNewLclvNode(thisTmp, type);
15416-
15417-
// If this is invoked during global morph we are adding code to a remote tree
15418-
// Despite this being a store, we can't meaningfully add assertions
15419-
//
15420-
thisStore->SetMorphed(this);
1542115438
}
1542215439

1542315440
if (flagVal->IsIntegralConst())
@@ -15435,11 +15452,6 @@ GenTree* Compiler::gtOptimizeEnumHasFlag(GenTree* thisOp, GenTree* flagOp)
1543515452
flagStoreStmt->SetRootNode(flagStore);
1543615453
flagValOpt = gtNewLclvNode(flagTmp, type);
1543715454
flagValOptCopy = gtNewLclvNode(flagTmp, type);
15438-
15439-
// If this is invoked during global morph we are adding code to a remote tree
15440-
// Despite this being a store, we can't meaningfully add assertions
15441-
//
15442-
flagStore->SetMorphed(this);
1544315455
}
1544415456

1544515457
// Turn the call into (thisValTmp & flagTmp) == flagTmp.
@@ -17424,7 +17436,16 @@ void Compiler::gtExtractSideEffList(GenTree* expr,
1742417436
}
1742517437

1742617438
GenTree* comma = m_compiler->gtNewOperNode(GT_COMMA, TYP_VOID, m_result, node);
17427-
comma->SetMorphed(m_compiler);
17439+
17440+
#ifdef DEBUG
17441+
if (m_compiler->fgGlobalMorph)
17442+
{
17443+
// Either both should be morphed or neither should be.
17444+
assert((m_result->gtDebugFlags & GTF_DEBUG_NODE_MORPHED) ==
17445+
(node->gtDebugFlags & GTF_DEBUG_NODE_MORPHED));
17446+
comma->gtDebugFlags |= node->gtDebugFlags & GTF_DEBUG_NODE_MORPHED;
17447+
}
17448+
#endif
1742817449

1742917450
// Both should have valuenumbers defined for both or for neither
1743017451
// one (unless we are remorphing, in which case a prior transform
@@ -30741,7 +30762,12 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree)
3074130762
}
3074230763

3074330764
vecCon->gtSimdVal = simdVal;
30744-
vecCon->SetMorphed(this);
30765+
30766+
if (fgGlobalMorph)
30767+
{
30768+
INDEBUG(vecCon->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
30769+
}
30770+
3074530771
fgUpdateConstTreeValueNumber(vecCon);
3074630772
return vecCon;
3074730773
}
@@ -30803,7 +30829,11 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree)
3080330829
#endif // !TARGET_XARCH && !TARGET_ARM64
3080430830

3080530831
DEBUG_DESTROY_NODE(op, tree);
30806-
vectorNode->SetMorphed(this);
30832+
30833+
if (fgGlobalMorph)
30834+
{
30835+
INDEBUG(vectorNode->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
30836+
}
3080730837
return vectorNode;
3080830838
}
3080930839
}
@@ -31988,10 +32018,17 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree)
3198832018

3198932019
if (resultNode != tree)
3199032020
{
31991-
resultNode->SetMorphed(this);
31992-
if (resultNode->OperIs(GT_COMMA))
32021+
if (fgGlobalMorph)
3199332022
{
31994-
resultNode->AsOp()->gtGetOp2()->SetMorphed(this);
32023+
// We can sometimes produce a comma over the constant if the original op
32024+
// had a side effect or even a new constant node, so just ensure we set
32025+
// the flag (which will be already set for the operands otherwise).
32026+
INDEBUG(resultNode->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
32027+
32028+
if (resultNode->OperIs(GT_COMMA))
32029+
{
32030+
INDEBUG(resultNode->AsOp()->gtGetOp2()->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
32031+
}
3199532032
}
3199632033

3199732034
if (resultNode->OperIsConst())
@@ -32118,65 +32155,3 @@ bool Compiler::gtCanSkipCovariantStoreCheck(GenTree* value, GenTree* array)
3211832155

3211932156
return false;
3212032157
}
32121-
32122-
#if defined(DEBUG)
32123-
//------------------------------------------------------------------------
32124-
// SetMorphed: mark a node as having been morphed
32125-
//
32126-
// Arguments:
32127-
// compiler - compiler instance
32128-
// doChildren - recursive mark child nodes
32129-
//
32130-
// Notes:
32131-
// Does nothing outside of global morph.
32132-
//
32133-
// Useful for morph post-order expansions / optimizations.
32134-
//
32135-
// Use care when invoking this on an assignment (or when doChildren is true,
32136-
// on trees containing assignments) as those usually will also require
32137-
// local assertion updates.
32138-
//
32139-
void GenTree::SetMorphed(Compiler* compiler, bool doChildren /* = false */)
32140-
{
32141-
if (!compiler->fgGlobalMorph)
32142-
{
32143-
return;
32144-
}
32145-
32146-
struct Visitor : GenTreeVisitor<Visitor>
32147-
{
32148-
enum
32149-
{
32150-
DoPostOrder = true,
32151-
};
32152-
32153-
Visitor(Compiler* comp)
32154-
: GenTreeVisitor(comp)
32155-
{
32156-
}
32157-
32158-
fgWalkResult PostOrderVisit(GenTree** use, GenTree* user)
32159-
{
32160-
GenTree* const node = *use;
32161-
if (!node->WasMorphed())
32162-
{
32163-
node->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED;
32164-
node->gtMorphCount++;
32165-
}
32166-
return Compiler::WALK_CONTINUE;
32167-
}
32168-
};
32169-
32170-
if (doChildren)
32171-
{
32172-
Visitor v(compiler);
32173-
GenTree* node = this;
32174-
v.WalkTree(&node, nullptr);
32175-
}
32176-
else if (!WasMorphed())
32177-
{
32178-
gtDebugFlags |= GTF_DEBUG_NODE_MORPHED;
32179-
gtMorphCount++;
32180-
}
32181-
}
32182-
#endif

src/coreclr/jit/gentree.h

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -602,21 +602,21 @@ inline GenTreeFlags& operator ^=(GenTreeFlags& a, GenTreeFlags b)
602602
//------------------------------------------------------------------------
603603
// GenTreeDebugFlags: a bitmask of debug-only flags for GenTree stored in gtDebugFlags
604604
//
605-
enum GenTreeDebugFlags : unsigned short
605+
enum GenTreeDebugFlags : unsigned int
606606
{
607-
GTF_DEBUG_NONE = 0x0000, // No debug flags.
607+
GTF_DEBUG_NONE = 0x00000000, // No debug flags.
608608

609-
GTF_DEBUG_NODE_MORPHED = 0x0001, // the node has been morphed (in the global morphing phase)
610-
GTF_DEBUG_NODE_SMALL = 0x0002,
611-
GTF_DEBUG_NODE_LARGE = 0x0004,
612-
GTF_DEBUG_NODE_CG_PRODUCED = 0x0008, // genProduceReg has been called on this node
613-
GTF_DEBUG_NODE_CG_CONSUMED = 0x0010, // genConsumeReg has been called on this node
614-
GTF_DEBUG_NODE_LSRA_ADDED = 0x0020, // This node was added by LSRA
609+
GTF_DEBUG_NODE_MORPHED = 0x00000001, // the node has been morphed (in the global morphing phase)
610+
GTF_DEBUG_NODE_SMALL = 0x00000002,
611+
GTF_DEBUG_NODE_LARGE = 0x00000004,
612+
GTF_DEBUG_NODE_CG_PRODUCED = 0x00000008, // genProduceReg has been called on this node
613+
GTF_DEBUG_NODE_CG_CONSUMED = 0x00000010, // genConsumeReg has been called on this node
614+
GTF_DEBUG_NODE_LSRA_ADDED = 0x00000020, // This node was added by LSRA
615615

616-
GTF_DEBUG_NODE_MASK = 0x003F, // These flags are all node (rather than operation) properties.
616+
GTF_DEBUG_NODE_MASK = 0x0000003F, // These flags are all node (rather than operation) properties.
617617

618-
GTF_DEBUG_VAR_CSE_REF = 0x8000, // GT_LCL_VAR -- This is a CSE LCL_VAR node
619-
GTF_DEBUG_CAST_DONT_FOLD = 0x4000, // GT_CAST -- Try to prevent this cast from being folded
618+
GTF_DEBUG_VAR_CSE_REF = 0x00800000, // GT_LCL_VAR -- This is a CSE LCL_VAR node
619+
GTF_DEBUG_CAST_DONT_FOLD = 0x00400000, // GT_CAST -- Try to prevent this cast from being folded
620620
};
621621

622622
inline constexpr GenTreeDebugFlags operator ~(GenTreeDebugFlags a)
@@ -972,26 +972,7 @@ struct GenTree
972972

973973
#if defined(DEBUG)
974974
GenTreeDebugFlags gtDebugFlags;
975-
unsigned short gtMorphCount;
976-
void SetMorphed(Compiler* compiler, bool doChilren = false);
977-
978-
bool WasMorphed() const
979-
{
980-
return (gtDebugFlags & GTF_DEBUG_NODE_MORPHED) != 0;
981-
}
982-
983-
void ClearMorphed()
984-
{
985-
gtDebugFlags &= ~GTF_DEBUG_NODE_MORPHED;
986-
}
987-
#else
988-
void SetMorphed(Compiler* compiler, bool doChildren = false)
989-
{
990-
}
991-
void ClearMorphed()
992-
{
993-
}
994-
#endif
975+
#endif // defined(DEBUG)
995976

996977
ValueNumPair gtVNPair;
997978

0 commit comments

Comments
 (0)