diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 07fbe157a92ce..b9bfbc774ca88 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -4108,6 +4108,7 @@ class Compiler static LONG jitNestingLevel; #endif // DEBUG + static bool impIsInvariant(const GenTree* tree); static bool impIsAddressInLocal(const GenTree* tree, GenTree** lclVarTreeOut = nullptr); void impMakeDiscretionaryInlineObservations(InlineInfo* pInlineInfo, InlineResult* inlineResult); diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 64b87366b3229..cace833e57372 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -16308,7 +16308,7 @@ bool GenTree::IsLocalExpr(Compiler* comp, GenTreeLclVarCommon** pLclVarTree, Fie // If this tree evaluates some sum of a local address and some constants, // return the node for the local being addressed -GenTreeLclVarCommon* GenTree::IsLocalAddrExpr() +const GenTreeLclVarCommon* GenTree::IsLocalAddrExpr() const { if (OperGet() == GT_ADDR) { @@ -22865,7 +22865,7 @@ bool GenTreeLclFld::IsOffsetMisaligned() const bool GenTree::IsInvariant() const { - return OperIsConst() || Compiler::impIsAddressInLocal(this); + return OperIsConst() || IsLocalAddrExpr(); } //------------------------------------------------------------------------ diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 82c16748f86e3..05746ae156ec2 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -1916,7 +1916,11 @@ struct GenTree // Simpler variant of the above which just returns the local node if this is an expression that // yields an address into a local - GenTreeLclVarCommon* IsLocalAddrExpr(); + const GenTreeLclVarCommon* IsLocalAddrExpr() const; + GenTreeLclVarCommon* IsLocalAddrExpr() + { + return const_cast(static_cast(this)->IsLocalAddrExpr()); + } // Determine if this tree represents the value of an entire implicit byref parameter, // and if so return the tree for the parameter. diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 9f8ace666f09c..8999bd0f192a9 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -18902,14 +18902,39 @@ bool Compiler::impIsValueType(typeInfo* pTypeInfo) } } -/***************************************************************************** - * Check to see if the tree is the address of a local or - the address of a field in a local. - - *lclVarTreeOut will contain the GT_LCL_VAR tree when it returns true. - - */ +//------------------------------------------------------------------------ +// impIsInvariant: check if a tree (created during import) is invariant. +// +// Arguments: +// tree -- The tree +// +// Returns: +// true if it is invariant +// +// Remarks: +// This is a variant of GenTree::IsInvariant that is more suitable for use +// during import. Unlike that function, this one handles GT_FIELD nodes. +// +bool Compiler::impIsInvariant(const GenTree* tree) +{ + return tree->OperIsConst() || impIsAddressInLocal(tree); +} +//------------------------------------------------------------------------ +// impIsAddressInLocal: +// Check to see if the tree is the address of a local or +// the address of a field in a local. +// Arguments: +// tree -- The tree +// lclVarTreeOut -- [out] the local that this points into +// +// Returns: +// true if it points into a local +// +// Remarks: +// This is a variant of GenTree::IsLocalAddrExpr that is more suitable for +// use during import. Unlike that function, this one handles GT_FIELD nodes. +// bool Compiler::impIsAddressInLocal(const GenTree* tree, GenTree** lclVarTreeOut) { if (tree->gtOper != GT_ADDR) @@ -19520,7 +19545,7 @@ void Compiler::impInlineRecordArgInfo(InlineInfo* pInlineInfo, INDEBUG(curArgVal->AsLclVar()->gtLclILoffs = argNum;) } - if (curArgVal->IsInvariant()) + if (impIsInvariant(curArgVal)) { inlCurArgInfo->argIsInvariant = true; if (inlCurArgInfo->argIsThis && (curArgVal->gtOper == GT_CNS_INT) && (curArgVal->AsIntCon()->gtIconVal == 0))