From db5c43370d41cc8efa6c4908c2a74daeb83462db Mon Sep 17 00:00:00 2001 From: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com> Date: Thu, 22 Sep 2022 16:43:37 +0300 Subject: [PATCH] Delete `GTF_VAR_CAST` (#74461) It is unused. Tighten an assert in the ref counter. --- src/coreclr/jit/compiler.cpp | 4 --- src/coreclr/jit/gentree.cpp | 6 ----- src/coreclr/jit/gentree.h | 21 +++++++-------- src/coreclr/jit/lclvars.cpp | 49 +++++----------------------------- src/coreclr/jit/morph.cpp | 10 +++---- src/coreclr/jit/morphblock.cpp | 1 - src/coreclr/jit/optimizer.cpp | 6 ----- src/coreclr/jit/valuenum.cpp | 3 ++- 8 files changed, 22 insertions(+), 78 deletions(-) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index fae7eddfa4c..334af8b06bd 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -9218,10 +9218,6 @@ void cTreeFlags(Compiler* comp, GenTree* tree) { chars += printf("[VAR_USEASG]"); } - if (tree->gtFlags & GTF_VAR_CAST) - { - chars += printf("[VAR_CAST]"); - } if (tree->gtFlags & GTF_VAR_ITERATOR) { chars += printf("[VAR_ITERATOR]"); diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 5ba22397689..43d6d550f4e 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -10442,12 +10442,6 @@ void Compiler::gtDispNode(GenTree* tree, IndentStack* indentStack, _In_ _In_opt_ --msgLength; break; } - if (tree->gtFlags & GTF_VAR_CAST) - { - printf("C"); - --msgLength; - break; - } if (tree->gtFlags & GTF_VAR_CONTEXT) { printf("!"); diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 205644138c2..81b04064879 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -468,11 +468,10 @@ enum GenTreeFlags : unsigned int GTF_LIVENESS_MASK = GTF_VAR_DEF | GTF_VAR_USEASG | GTF_VAR_DEATH_MASK, - GTF_VAR_CAST = 0x01000000, // GT_LCL_VAR -- has been explicitly cast (variable node may not be type of local) - GTF_VAR_ITERATOR = 0x00800000, // GT_LCL_VAR -- this is a iterator reference in the loop condition - GTF_VAR_CLONED = 0x00400000, // GT_LCL_VAR -- this node has been cloned or is a clone - GTF_VAR_CONTEXT = 0x00200000, // GT_LCL_VAR -- this node is part of a runtime lookup - GTF_VAR_FOLDED_IND = 0x00100000, // GT_LCL_VAR -- this node was folded from *(typ*)&lclVar expression tree in fgMorphSmpOp() + GTF_VAR_ITERATOR = 0x01000000, // GT_LCL_VAR -- this is a iterator reference in the loop condition + GTF_VAR_CLONED = 0x00800000, // GT_LCL_VAR -- this node has been cloned or is a clone + GTF_VAR_CONTEXT = 0x00400000, // GT_LCL_VAR -- this node is part of a runtime lookup + GTF_VAR_FOLDED_IND = 0x00200000, // GT_LCL_VAR -- this node was folded from *(typ*)&lclVar expression tree in fgMorphSmpOp() // where 'typ' is a small type and 'lclVar' corresponds to a normalized-on-store local variable. // This flag identifies such nodes in order to make sure that fgDoNormalizeOnStore() is called // on their parents in post-order morph. @@ -2313,20 +2312,18 @@ public: bool IsReuseRegVal() const { // This can be extended to non-constant nodes, but not to local or indir nodes. - if (IsInvariant() && ((gtFlags & GTF_REUSE_REG_VAL) != 0)) - { - return true; - } - return false; + return OperIsConst() && ((gtFlags & GTF_REUSE_REG_VAL) != 0); } + void SetReuseRegVal() { - assert(IsInvariant()); + assert(OperIsConst()); gtFlags |= GTF_REUSE_REG_VAL; } + void ResetReuseRegVal() { - assert(IsInvariant()); + assert(OperIsConst()); gtFlags &= ~GTF_REUSE_REG_VAL; } diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index a694d31c39b..620a2310d51 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -4452,7 +4452,7 @@ void Compiler::lvaMarkLclRefs(GenTree* tree, BasicBlock* block, Statement* stmt, #if FEATURE_PARTIAL_SIMD_CALLEE_SAVE // TODO-CQ: If the varType needs partial callee save, conservatively do not enregister - // such variable. In future, need to enable enregisteration for such variables. + // such variable. In future, we should enable enregisteration for such variables. if (!varTypeNeedsPartialCalleeSave(varDsc->GetRegisterType())) #endif { @@ -4463,48 +4463,11 @@ void Compiler::lvaMarkLclRefs(GenTree* tree, BasicBlock* block, Statement* stmt, } } - bool allowStructs = false; -#ifdef UNIX_AMD64_ABI - // On System V the type of the var could be a struct type. - allowStructs = varTypeIsStruct(varDsc); -#endif // UNIX_AMD64_ABI - - /* Variables must be used as the same type throughout the method */ - noway_assert(varDsc->lvType == TYP_UNDEF || tree->gtType == TYP_UNKNOWN || allowStructs || - genActualType(varDsc->TypeGet()) == genActualType(tree->gtType) || - (tree->gtType == TYP_BYREF && varDsc->TypeGet() == TYP_I_IMPL) || - (tree->gtType == TYP_I_IMPL && varDsc->TypeGet() == TYP_BYREF) || (tree->gtFlags & GTF_VAR_CAST) || - (varTypeIsFloating(varDsc) && varTypeIsFloating(tree)) || - (varTypeIsStruct(varDsc) == varTypeIsStruct(tree))); - - /* Remember the type of the reference */ - - if (tree->gtType == TYP_UNKNOWN || varDsc->lvType == TYP_UNDEF) - { - varDsc->lvType = tree->gtType; - noway_assert(genActualType(varDsc->TypeGet()) == tree->gtType); // no truncation - } - -#ifdef DEBUG - if (tree->gtFlags & GTF_VAR_CAST) - { - // it should never be bigger than the variable slot - - // Trees don't store the full information about structs - // so we can't check them. - if (tree->TypeGet() != TYP_STRUCT) - { - unsigned treeSize = genTypeSize(tree->TypeGet()); - unsigned varSize = genTypeSize(varDsc->TypeGet()); - if (varDsc->TypeGet() == TYP_STRUCT) - { - varSize = varDsc->lvSize(); - } - - assert(treeSize <= varSize); - } - } -#endif + // Check that the LCL_VAR node has the same type as the underlying variable, save a few mismatches we allow. + assert(tree->TypeIs(varDsc->TypeGet(), genActualType(varDsc)) || + (tree->TypeIs(TYP_I_IMPL) && (varDsc->TypeGet() == TYP_BYREF)) || // Created for spill clique import. + (tree->TypeIs(TYP_BYREF) && (varDsc->TypeGet() == TYP_I_IMPL)) || // Created by inliner substitution. + (tree->TypeIs(TYP_INT) && (varDsc->TypeGet() == TYP_LONG))); // Created by "optNarrowTree". } } diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index e015597e1d8..f1c7d633077 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -4548,8 +4548,8 @@ GenTree* Compiler::fgMorphIndexAddr(GenTreeIndexAddr* indexAddr) { unsigned arrRefTmpNum = lvaGrabTemp(true DEBUGARG("arr expr")); arrRefDefn = gtNewTempAssign(arrRefTmpNum, arrRef); - arrRef = gtNewLclvNode(arrRefTmpNum, arrRef->TypeGet()); - arrRef2 = gtNewLclvNode(arrRefTmpNum, arrRef->TypeGet()); + arrRef = gtNewLclvNode(arrRefTmpNum, lvaGetDesc(arrRefTmpNum)->TypeGet()); + arrRef2 = gtNewLclvNode(arrRefTmpNum, lvaGetDesc(arrRefTmpNum)->TypeGet()); } else { @@ -4563,8 +4563,8 @@ GenTree* Compiler::fgMorphIndexAddr(GenTreeIndexAddr* indexAddr) { unsigned indexTmpNum = lvaGrabTemp(true DEBUGARG("index expr")); indexDefn = gtNewTempAssign(indexTmpNum, index); - index = gtNewLclvNode(indexTmpNum, index->TypeGet()); - index2 = gtNewLclvNode(indexTmpNum, index->TypeGet()); + index = gtNewLclvNode(indexTmpNum, lvaGetDesc(indexTmpNum)->TypeGet()); + index2 = gtNewLclvNode(indexTmpNum, lvaGetDesc(indexTmpNum)->TypeGet()); } else { @@ -17285,7 +17285,7 @@ bool Compiler::fgMorphArrayOpsStmt(MorphMDArrayTempCache* pTempCache, BasicBlock // Side-effect; create a temp. // unsigned newIdxLcl = m_compiler->lvaGrabTemp(true DEBUGARG("MD array index copy")); unsigned newIdxLcl = m_pTempCache->GrabTemp(idx->TypeGet()); - GenTree* newIdx = m_compiler->gtNewLclvNode(newIdxLcl, idx->TypeGet()); + GenTree* newIdx = m_compiler->gtNewLclvNode(newIdxLcl, genActualType(idx)); idxToUse[i] = newIdx; idxToCopy[i] = newIdxLcl; anyIdxWithSideEffects = true; diff --git a/src/coreclr/jit/morphblock.cpp b/src/coreclr/jit/morphblock.cpp index 20638c459e4..ae970e0b25d 100644 --- a/src/coreclr/jit/morphblock.cpp +++ b/src/coreclr/jit/morphblock.cpp @@ -1432,7 +1432,6 @@ GenTree* MorphCopyBlockHelper::CopyFieldByField() (m_srcVarDsc->lvType == TYP_STRUCT) ? m_srcVarDsc->lvExactSize : genTypeSize(m_srcVarDsc); if (destSize == srcSize) { - m_srcLclNode->gtFlags |= GTF_VAR_CAST; m_srcLclNode->ChangeOper(GT_LCL_FLD); m_srcLclNode->gtType = destType; m_comp->lvaSetVarDoNotEnregister(m_srcLclNum DEBUGARG(DoNotEnregisterReason::LocalField)); diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 0c12611a40b..8635dc63e9c 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -5850,12 +5850,6 @@ bool Compiler::optNarrowTree(GenTree* tree, var_types srct, var_types dstt, Valu tree->gtType = dstt; tree->SetVNs(vnpNarrow); - - /* Make sure we don't mess up the variable type */ - if ((oper == GT_LCL_VAR) || (oper == GT_LCL_FLD)) - { - tree->gtFlags |= GTF_VAR_CAST; - } } return true; diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 53fbc752ef6..5ea27c4b866 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -8512,7 +8512,8 @@ void Compiler::fgValueNumberTree(GenTree* tree) } else { - assert((varDsc->TypeGet() == TYP_I_IMPL) && lcl->TypeIs(TYP_BYREF)); + assert(((varDsc->TypeGet() == TYP_I_IMPL) && lcl->TypeIs(TYP_BYREF)) || + ((varDsc->TypeGet() == TYP_BYREF) && lcl->TypeIs(TYP_I_IMPL))); lcl->gtVNPair = wholeLclVarVNP; } } -- GitLab