diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index 87310728dd28b..4dc279b589dd1 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -1026,6 +1026,30 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #endif // !defined(TARGET_64BIT) + //------------------------------------------------------------------------- + // genUpdateLifeStore: Do liveness udpate after tree store instructions + // were emitted, update result var's home if it was stored on stack. + // + // Arguments: + // tree - Gentree node + // targetReg - of the tree + // varDsc - result value's variable + // + // Return Value: + // None. + __forceinline void genUpdateLifeStore(GenTree* tree, regNumber targetReg, LclVarDsc* varDsc) + { + if (targetReg != REG_NA) + { + genProduceReg(tree); + } + else + { + genUpdateLife(tree); + varDsc->SetRegNum(REG_STK); + } + } + // Do liveness update for register produced by the current node in codegen after // code has been emitted for it. void genProduceReg(GenTree* tree); diff --git a/src/coreclr/jit/codegenarm.cpp b/src/coreclr/jit/codegenarm.cpp index cc91d1bc435e9..079dcdd6da79e 100644 --- a/src/coreclr/jit/codegenarm.cpp +++ b/src/coreclr/jit/codegenarm.cpp @@ -1116,19 +1116,14 @@ void CodeGen::genCodeForStoreLclVar(GenTreeLclVar* tree) emitter* emit = GetEmitter(); emit->emitIns_S_R(ins, attr, dataReg, varNum, /* offset */ 0); - - // Updating variable liveness after instruction was emitted - genUpdateLife(tree); - - varDsc->SetRegNum(REG_STK); } else // store into register (i.e move into register) { // Assign into targetReg when dataReg (from op1) is not the same register inst_Mov(targetType, targetReg, dataReg, /* canSkip */ true); - - genProduceReg(tree); } + + genUpdateLifeStore(tree, targetReg, varDsc); } } } diff --git a/src/coreclr/jit/codegenarm64.cpp b/src/coreclr/jit/codegenarm64.cpp index 17fa38771b05a..dae6ea2105208 100644 --- a/src/coreclr/jit/codegenarm64.cpp +++ b/src/coreclr/jit/codegenarm64.cpp @@ -2928,7 +2928,6 @@ void CodeGen::genCodeForStoreLclVar(GenTreeLclVar* lclNode) if (targetReg != REG_NA) { emit->emitIns_R_I(INS_movi, emitActualTypeSize(targetType), targetReg, 0x00, INS_OPTS_16B); - genProduceReg(lclNode); } else { @@ -2941,8 +2940,8 @@ void CodeGen::genCodeForStoreLclVar(GenTreeLclVar* lclNode) assert(targetType == TYP_SIMD8); GetEmitter()->emitIns_S_R(INS_str, EA_8BYTE, REG_ZR, varNum, 0); } - genUpdateLife(lclNode); } + genUpdateLifeStore(lclNode, targetReg, varDsc); return; } if (zeroInit) @@ -2971,18 +2970,13 @@ void CodeGen::genCodeForStoreLclVar(GenTreeLclVar* lclNode) emitAttr attr = emitActualTypeSize(targetType); emit->emitIns_S_R(ins, attr, dataReg, varNum, /* offset */ 0); - - genUpdateLife(lclNode); - - varDsc->SetRegNum(REG_STK); } else // store into register (i.e move into register) { // Assign into targetReg when dataReg (from op1) is not the same register inst_Mov(targetType, targetReg, dataReg, /* canSkip */ true); - - genProduceReg(lclNode); } + genUpdateLifeStore(lclNode, targetReg, varDsc); } } @@ -5266,8 +5260,9 @@ void CodeGen::genStoreLclTypeSimd12(GenTreeLclVarCommon* treeNode) { assert(treeNode->OperIs(GT_STORE_LCL_FLD, GT_STORE_LCL_VAR)); - unsigned offs = treeNode->GetLclOffs(); - unsigned varNum = treeNode->GetLclNum(); + unsigned offs = treeNode->GetLclOffs(); + unsigned varNum = treeNode->GetLclNum(); + LclVarDsc* varDsc = compiler->lvaGetDesc(varNum); assert(varNum < compiler->lvaCount); GenTree* data = treeNode->gtGetOp1(); @@ -5285,8 +5280,6 @@ void CodeGen::genStoreLclTypeSimd12(GenTreeLclVarCommon* treeNode) // Update life after instruction emitted genUpdateLife(treeNode); - - LclVarDsc* varDsc = compiler->lvaGetDesc(varNum); varDsc->SetRegNum(REG_STK); return; @@ -5301,20 +5294,14 @@ void CodeGen::genStoreLclTypeSimd12(GenTreeLclVarCommon* treeNode) assert(GetEmitter()->isVectorRegister(tgtReg)); inst_Mov(treeNode->TypeGet(), tgtReg, dataReg, /* canSkip */ true); - genProduceReg(treeNode); } else { // Need an additional integer register to extract upper 4 bytes from data. regNumber tmpReg = treeNode->GetSingleTempReg(); GetEmitter()->emitStoreSimd12ToLclOffset(varNum, offs, dataReg, tmpReg); - - // Update life after instruction emitted - genUpdateLife(treeNode); - - LclVarDsc* varDsc = compiler->lvaGetDesc(varNum); - varDsc->SetRegNum(REG_STK); } + genUpdateLifeStore(treeNode, tgtReg, varDsc); } #endif // FEATURE_SIMD diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index c6abbde39ed53..917153d719e83 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -4931,17 +4931,7 @@ void CodeGen::genCodeForStoreLclFld(GenTreeLclFld* tree) { GetEmitter()->emitInsBinary(ins_Store(targetType), emitTypeSize(tree), tree, op1); } - - // Updating variable liveness after instruction was emitted - if (targetReg != REG_NA) - { - genProduceReg(tree); - } - else - { - genUpdateLife(tree); - varDsc->SetRegNum(REG_STK); - } + genUpdateLifeStore(tree, targetReg, varDsc); } //------------------------------------------------------------------------ @@ -5060,16 +5050,7 @@ void CodeGen::genCodeForStoreLclVar(GenTreeLclVar* lclNode) emitTypeSize(targetType)); } } - // Updating variable liveness after instruction was emitted - if (targetReg != REG_NA) - { - genProduceReg(lclNode); - } - else - { - genUpdateLife(lclNode); - varDsc->SetRegNum(REG_STK); - } + genUpdateLifeStore(lclNode, targetReg, varDsc); } } diff --git a/src/coreclr/jit/simdcodegenxarch.cpp b/src/coreclr/jit/simdcodegenxarch.cpp index d02d760ffdc66..cbe18a610f3ab 100644 --- a/src/coreclr/jit/simdcodegenxarch.cpp +++ b/src/coreclr/jit/simdcodegenxarch.cpp @@ -236,8 +236,9 @@ void CodeGen::genStoreLclTypeSimd12(GenTreeLclVarCommon* treeNode) GenTree* data = treeNode->Data(); assert(!data->isContained()); - regNumber tgtReg = treeNode->GetRegNum(); - regNumber dataReg = genConsumeReg(data); + regNumber tgtReg = treeNode->GetRegNum(); + regNumber dataReg = genConsumeReg(data); + LclVarDsc* varDsc = compiler->lvaGetDesc(varNum); if (tgtReg != REG_NA) { @@ -245,7 +246,6 @@ void CodeGen::genStoreLclTypeSimd12(GenTreeLclVarCommon* treeNode) assert(genIsValidFloatReg(tgtReg)); inst_Mov(treeNode->TypeGet(), tgtReg, dataReg, /* canSkip */ true); - genProduceReg(treeNode); } else { @@ -272,13 +272,9 @@ void CodeGen::genStoreLclTypeSimd12(GenTreeLclVarCommon* treeNode) // Store upper 4 bytes emit->emitIns_S_R(INS_movss, EA_4BYTE, tmpReg, varNum, offs + 8); } - - // Update the life of treeNode - genUpdateLife(treeNode); - - LclVarDsc* varDsc = compiler->lvaGetDesc(varNum); - varDsc->SetRegNum(REG_STK); } + + genUpdateLifeStore(treeNode, tgtReg, varDsc); } //-----------------------------------------------------------------------------