From 61f713e86d2de1267638769925733b1e609e040b Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 3 Sep 2021 20:50:30 -0700 Subject: [PATCH 1/3] Do not allocate register if ZeroInit/EHWriteThru --- src/coreclr/jit/lsra.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index 9491b2c0773578..d7e1f35891123f 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -4945,6 +4945,12 @@ void LinearScan::allocateRegisters() // it to a different register file. allocate = false; } + else if ((currentInterval->isWriteThru) && (refType == RefTypeZeroInit)) + { + // For RefTypeZeroInit which is a write thru, there is no need to allocate register + // right away. It can be assigned when actually definition occurs. + allocate = false; + } if (!allocate) { INDEBUG(dumpLsraAllocationEvent(LSRA_EVENT_NO_ENTRY_REG_ALLOCATED, currentInterval)); From 64c8cc9f36c78083cba26af2af0d7db362da4e54 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 3 Sep 2021 21:17:38 -0700 Subject: [PATCH 2/3] Update the comments about zero-init heuristics --- src/coreclr/jit/lclvars.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 27771bbb7c18ce..2c01b20dc24a93 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -4142,8 +4142,9 @@ void Compiler::lvaMarkLclRefs(GenTree* tree, BasicBlock* block, Statement* stmt, { bool bbInALoop = (block->bbFlags & BBF_BACKWARD_JUMP) != 0; bool bbIsReturn = block->bbJumpKind == BBJ_RETURN; - // TODO: Zero-inits in LSRA are created with below condition. Try to use similar condition here as well. - // if (compiler->info.compInitMem || varTypeIsGC(varDsc->TypeGet())) + // TODO: Zero-inits in LSRA are created with below condition. But if filter out based on that condition + // we filter lot of interesting variables that would benefit otherwise with EH var enregistration. + //bool needsExplicitZeroInit = !varDsc->lvIsParam && (info.compInitMem || varTypeIsGC(varDsc->TypeGet())); bool needsExplicitZeroInit = fgVarNeedsExplicitZeroInit(lclNum, bbInALoop, bbIsReturn); if (varDsc->lvSingleDefRegCandidate || needsExplicitZeroInit) From e6f0ae82b674e11709cc1be393b691eeedbc700d Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 6 Sep 2021 00:02:35 -0700 Subject: [PATCH 3/3] jit format --- src/coreclr/jit/lclvars.cpp | 3 ++- src/coreclr/jit/lsra.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 2c01b20dc24a93..f7930cfa6b58cd 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -4144,7 +4144,8 @@ void Compiler::lvaMarkLclRefs(GenTree* tree, BasicBlock* block, Statement* stmt, bool bbIsReturn = block->bbJumpKind == BBJ_RETURN; // TODO: Zero-inits in LSRA are created with below condition. But if filter out based on that condition // we filter lot of interesting variables that would benefit otherwise with EH var enregistration. - //bool needsExplicitZeroInit = !varDsc->lvIsParam && (info.compInitMem || varTypeIsGC(varDsc->TypeGet())); + // bool needsExplicitZeroInit = !varDsc->lvIsParam && (info.compInitMem || + // varTypeIsGC(varDsc->TypeGet())); bool needsExplicitZeroInit = fgVarNeedsExplicitZeroInit(lclNum, bbInALoop, bbIsReturn); if (varDsc->lvSingleDefRegCandidate || needsExplicitZeroInit) diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index d7e1f35891123f..58e55bae823348 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -4949,6 +4949,7 @@ void LinearScan::allocateRegisters() { // For RefTypeZeroInit which is a write thru, there is no need to allocate register // right away. It can be assigned when actually definition occurs. + // In future, see if avoiding allocation for RefTypeZeroInit gives any benefit in general. allocate = false; } if (!allocate)