From 9e5d843c96634b619a22d318594a90dbd463802f Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Thu, 2 Feb 2023 23:11:15 +0100 Subject: [PATCH] Allow inlining for ldsfld + value-type (#78736) --- src/coreclr/jit/importer.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 34db37c..53e5104 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -9236,11 +9236,20 @@ void Compiler::impImportBlockCode(BasicBlock* block) { // Loading a static valuetype field usually will cause a JitHelper to be called // for the static base. This will bloat the code. - compInlineResult->Note(InlineObservation::CALLEE_LDFLD_STATIC_VALUECLASS); - if (compInlineResult->IsFailure()) + // Make an exception - small getters (6 bytes of IL) returning initialized fields, e.g.: + // + // static DateTime Foo { get; } = DateTime.Now; + // + bool isInitedFld = (opcode == CEE_LDSFLD) && (info.compILCodeSize <= 6) && + (fieldInfo.fieldFlags & CORINFO_FLG_FIELD_FINAL); + if (!isInitedFld) { - return; + compInlineResult->Note(InlineObservation::CALLEE_LDFLD_STATIC_VALUECLASS); + if (compInlineResult->IsFailure()) + { + return; + } } } } -- 2.7.4