From 0e0b6102dc89a2992be1e9f075d4f0db8a78e18c Mon Sep 17 00:00:00 2001 From: Carol Eidt Date: Wed, 11 Nov 2020 13:58:49 -0800 Subject: [PATCH 1/3] Don't force unused reg arg to the stack. --- src/coreclr/src/jit/lsra.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/jit/lsra.cpp b/src/coreclr/src/jit/lsra.cpp index d24e1f1ff00970..5f60fb4bd70951 100644 --- a/src/coreclr/src/jit/lsra.cpp +++ b/src/coreclr/src/jit/lsra.cpp @@ -5596,8 +5596,12 @@ void LinearScan::allocateRegisters() { allocate = false; } - else if (refType == RefTypeParamDef && varDsc->lvRefCntWtd() <= BB_UNITY_WEIGHT) + else if (refType == RefTypeParamDef && (!currentRefPosition->lastUse || (currentInterval->physReg == REG_STK)) && varDsc->lvRefCntWtd() <= BB_UNITY_WEIGHT) { + // If this is a low ref-count parameter, and either it is *not* a last used (i.e. unused) or it's + // passed on the stack, don't allocate a register. + // Note that if this is an unused register parameter we don't want to set allocate to false because that + // will cause us to allocate stack space to spill it. allocate = false; } else if ((currentInterval->physReg == REG_STK) && nextRefPosition->treeNode->OperIs(GT_BITCAST)) From 29b9ff781cbc33d5161c7b4bef12050a287254f4 Mon Sep 17 00:00:00 2001 From: Carol Eidt Date: Wed, 11 Nov 2020 14:58:46 -0800 Subject: [PATCH 2/3] Formatting --- src/coreclr/src/jit/lsra.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/jit/lsra.cpp b/src/coreclr/src/jit/lsra.cpp index 5f60fb4bd70951..f7292114e5058a 100644 --- a/src/coreclr/src/jit/lsra.cpp +++ b/src/coreclr/src/jit/lsra.cpp @@ -5596,7 +5596,9 @@ void LinearScan::allocateRegisters() { allocate = false; } - else if (refType == RefTypeParamDef && (!currentRefPosition->lastUse || (currentInterval->physReg == REG_STK)) && varDsc->lvRefCntWtd() <= BB_UNITY_WEIGHT) + else if (refType == RefTypeParamDef && + (!currentRefPosition->lastUse || (currentInterval->physReg == REG_STK)) && + varDsc->lvRefCntWtd() <= BB_UNITY_WEIGHT) { // If this is a low ref-count parameter, and either it is *not* a last used (i.e. unused) or it's // passed on the stack, don't allocate a register. From 3e109fc6de59cb73696b7d2626b2c7ffdcff0c73 Mon Sep 17 00:00:00 2001 From: Carol Eidt Date: Thu, 12 Nov 2020 16:44:37 -0800 Subject: [PATCH 3/3] Feedback --- src/coreclr/src/jit/lsra.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/jit/lsra.cpp b/src/coreclr/src/jit/lsra.cpp index f7292114e5058a..b09b45d2fffd01 100644 --- a/src/coreclr/src/jit/lsra.cpp +++ b/src/coreclr/src/jit/lsra.cpp @@ -5596,11 +5596,10 @@ void LinearScan::allocateRegisters() { allocate = false; } - else if (refType == RefTypeParamDef && - (!currentRefPosition->lastUse || (currentInterval->physReg == REG_STK)) && - varDsc->lvRefCntWtd() <= BB_UNITY_WEIGHT) + else if (refType == RefTypeParamDef && (varDsc->lvRefCntWtd() <= BB_UNITY_WEIGHT) && + (!currentRefPosition->lastUse || (currentInterval->physReg == REG_STK))) { - // If this is a low ref-count parameter, and either it is *not* a last used (i.e. unused) or it's + // If this is a low ref-count parameter, and either it is used (def is not the last use) or it's // passed on the stack, don't allocate a register. // Note that if this is an unused register parameter we don't want to set allocate to false because that // will cause us to allocate stack space to spill it.