diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 27771bbb7c18ce..f7930cfa6b58cd 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -4142,8 +4142,10 @@ 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) diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index 9491b2c0773578..58e55bae823348 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -4945,6 +4945,13 @@ 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. + // In future, see if avoiding allocation for RefTypeZeroInit gives any benefit in general. + allocate = false; + } if (!allocate) { INDEBUG(dumpLsraAllocationEvent(LSRA_EVENT_NO_ENTRY_REG_ALLOCATED, currentInterval));