diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 671d5692ac4576..13036a6766425d 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -9592,6 +9592,11 @@ void cTreeFlags(Compiler* comp, GenTree* tree) chars += printf("[GTF_ICON_STATIC_BOX_PTR]"); break; + case GTF_ICON_STATIC_ADDR_PTR: + + chars += printf("[GTF_ICON_STATIC_ADDR_PTR]"); + break; + default: assert(!"a forgotten handle flag"); break; diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index 692eb10d12359e..8c5adef145de91 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -4189,6 +4189,12 @@ void emitter::emitDispCommentForHandle(size_t handle, size_t cookie, GenTreeFlag printf("%s %s for %s", commentPrefix, flag == GTF_ICON_STATIC_HDL ? "data" : "box", fieldName); return; } + + if (flag == GTF_ICON_STATIC_ADDR_PTR) + { + printf("%s static base addr cell", commentPrefix); + return; + } } if (handle == 0) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index dd1dc0e70d371e..9d44d19d3c2f68 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -11434,6 +11434,9 @@ void Compiler::gtDispConst(GenTree* tree) case GTF_ICON_STATIC_BOX_PTR: printf(" static box ptr"); break; + case GTF_ICON_STATIC_ADDR_PTR: + printf(" static base addr cell"); + break; default: printf(" UNKNOWN"); break; diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 790d14f2841779..d1ebcd0496d530 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -560,6 +560,7 @@ enum GenTreeFlags : unsigned int GTF_ICON_BBC_PTR = 0x0F000000, // GT_CNS_INT -- constant is a basic block count pointer GTF_ICON_STATIC_BOX_PTR = 0x10000000, // GT_CNS_INT -- constant is an address of the box for a STATIC_IN_HEAP field GTF_ICON_FIELD_SEQ = 0x11000000, // <--------> -- constant is a FieldSeq* (used only as VNHandle) + GTF_ICON_STATIC_ADDR_PTR = 0x13000000, // GT_CNS_INT -- constant is a pointer to a static base address // GTF_ICON_REUSE_REG_VAL = 0x00800000 // GT_CNS_INT -- GTF_REUSE_REG_VAL, defined above GTF_ICON_SIMD_COUNT = 0x00200000, // GT_CNS_INT -- constant is Vector.Count diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index bfecb034e6145c..822ec09a583ec0 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -4238,13 +4238,21 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT case CORINFO_FIELD_STATIC_RELOCATABLE: { #ifdef FEATURE_READYTORUN - assert(pFieldInfo->fieldLookup.accessType == InfoAccessType::IAT_VALUE); assert(fieldKind == FieldSeq::FieldKind::SimpleStatic); assert(innerFldSeq != nullptr); - GenTree* baseAddr = gtNewIconHandleNode((size_t)pFieldInfo->fieldLookup.addr, GTF_ICON_STATIC_HDL); - GenTree* offset = gtNewIconNode(pFieldInfo->offset, innerFldSeq); - op1 = gtNewOperNode(GT_ADD, TYP_I_IMPL, baseAddr, offset); + size_t fldAddr = (size_t)pFieldInfo->fieldLookup.addr; + if (pFieldInfo->fieldLookup.accessType == IAT_VALUE) + { + op1 = gtNewIconHandleNode(fldAddr, GTF_ICON_STATIC_HDL); + } + else + { + assert(pFieldInfo->fieldLookup.accessType == IAT_PVALUE); + op1 = gtNewIndOfIconHandleNode(TYP_I_IMPL, fldAddr, GTF_ICON_STATIC_ADDR_PTR, true); + } + GenTree* offset = gtNewIconNode(pFieldInfo->offset, innerFldSeq); + op1 = gtNewOperNode(GT_ADD, TYP_I_IMPL, op1, offset); #else unreached(); #endif // FEATURE_READYTORUN diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 16380ac8d1911b..4bbbbf96ef2d8d 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -5360,6 +5360,7 @@ GenTreeFlags ValueNumStore::GetFoldedArithOpResultHandleFlags(ValueNum vn) case GTF_ICON_CIDMID_HDL: case GTF_ICON_TLS_HDL: case GTF_ICON_STATIC_BOX_PTR: + case GTF_ICON_STATIC_ADDR_PTR: return GTF_ICON_CONST_PTR; case GTF_ICON_STATIC_HDL: case GTF_ICON_GLOBAL_PTR: diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 26fab2dab3d73d..84513502930dfc 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2141,12 +2141,21 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; helperId = ReadyToRunHelperId.GetThreadStaticBase; } - else if (!_compilation.HasLazyStaticConstructor(field.OwningType) && !field.HasGCStaticBase) + else if (!_compilation.HasLazyStaticConstructor(field.OwningType)) { fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_RELOCATABLE; - ISymbolNode baseAddress = _compilation.NodeFactory.TypeNonGCStaticsSymbol((MetadataType)field.OwningType); - pResult->fieldLookup.accessType = InfoAccessType.IAT_VALUE; - pResult->fieldLookup.addr = (void*)ObjectToHandle(baseAddress); + ISymbolNode baseAddr; + if (field.HasGCStaticBase) + { + pResult->fieldLookup.accessType = InfoAccessType.IAT_PVALUE; + baseAddr = _compilation.NodeFactory.TypeGCStaticsSymbol((MetadataType)field.OwningType); + } + else + { + pResult->fieldLookup.accessType = InfoAccessType.IAT_VALUE; + baseAddr = _compilation.NodeFactory.TypeNonGCStaticsSymbol((MetadataType)field.OwningType); + } + pResult->fieldLookup.addr = (void*)ObjectToHandle(baseAddr); } else {