From: Egor Bogatov Date: Thu, 2 Feb 2023 22:11:15 +0000 (+0100) Subject: Allow inlining for ldsfld + value-type (#78736) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~4258 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e5d843c96634b619a22d318594a90dbd463802f;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Allow inlining for ldsfld + value-type (#78736) --- 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; + } } } }