[release/6.0] Skip allocation for ZeroInit writeThru intervals (#58767)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Tue, 7 Sep 2021 23:30:26 +0000 (16:30 -0700)
committerGitHub <noreply@github.com>
Tue, 7 Sep 2021 23:30:26 +0000 (16:30 -0700)
* Do not allocate register if ZeroInit/EHWriteThru

* Update the comments about zero-init heuristics

* jit format

Co-authored-by: Kunal Pathak <Kunal.Pathak@microsoft.com>
src/coreclr/jit/lclvars.cpp
src/coreclr/jit/lsra.cpp

index 9c38b0d..df083c7 100644 (file)
@@ -4152,8 +4152,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)
index 9491b2c..58e55ba 100644 (file)
@@ -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));