From 97625a5225b09745579f347492701b422407b474 Mon Sep 17 00:00:00 2001 From: sivarv Date: Thu, 9 Feb 2017 11:27:29 -0800 Subject: [PATCH] Increase the field count limit to 3 for promoting a struct with no filed access. Commit migrated from https://github.com/dotnet/coreclr/commit/c511e7ee84d13fb9b9238c4432f7f3af4926d45c --- src/coreclr/src/jit/morph.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/jit/morph.cpp b/src/coreclr/src/jit/morph.cpp index fdc9e32..dabca57 100644 --- a/src/coreclr/src/jit/morph.cpp +++ b/src/coreclr/src/jit/morph.cpp @@ -17132,9 +17132,17 @@ void Compiler::fgPromoteStructs() // field accesses, but only block-level operations on the whole struct, if the struct // has only one or two fields, then doing those block operations field-wise is probably faster // than doing a whole-variable block operation (e.g., a hardware "copy loop" on x86). - // So if no fields are accessed independently, and there are three or more fields, + // Struct promotion also provides the following benefits: reduce stack frame size, + // reduce the need for zero init of stack frame and fine grained constant/copy prop. + // Asm diffs indicate that promoting structs up to 3 fields is a net size win. + // So if no fields are accessed independently, and there are four or more fields, // then do not promote. - if (structPromotionInfo.fieldCnt > 2 && !varDsc->lvFieldAccessed) + // + // TODO: Ideally we would want to consider the impact of whether the struct is + // passed as a parameter or assigned the return value of a call. Because once promoted, + // struct copying is done by field by field assignment instead of a more efficient + // rep.stos or xmm reg based copy. + if (structPromotionInfo.fieldCnt > 3 && !varDsc->lvFieldAccessed) { JITDUMP("Not promoting promotable struct local V%02u: #fields = %d, fieldAccessed = %d.\n", lclNum, structPromotionInfo.fieldCnt, varDsc->lvFieldAccessed); -- 2.7.4