Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring store liveness update #80539

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
BrianBohe marked this conversation as resolved.
Show resolved Hide resolved
// code has been emitted for it.
void genProduceReg(GenTree* tree);
Expand Down
9 changes: 2 additions & 7 deletions src/coreclr/jit/codegenarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
25 changes: 6 additions & 19 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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
Expand Down
23 changes: 2 additions & 21 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
}
}

Expand Down
14 changes: 5 additions & 9 deletions src/coreclr/jit/simdcodegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,16 @@ 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)
{
// Simply use mov if we move a SIMD12 reg to another SIMD12 reg
assert(genIsValidFloatReg(tgtReg));

inst_Mov(treeNode->TypeGet(), tgtReg, dataReg, /* canSkip */ true);
genProduceReg(treeNode);
}
else
{
Expand All @@ -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);
}

//-----------------------------------------------------------------------------
Expand Down