Skip to content

Commit 53b4cd0

Browse files
Move assignment rationalization to before the late helper expansion phases (#85585)
* Flags dump for STOREIND * gtNewAssignNode assert * Call morphing * GenTree::GetLayout fixup * If Conversion * Tail duplication * Costing * Move assignment rationalization before GC Poll insertion * Block morphing (part 1) * Block morphing: switch dst<->src around * Finish block morphing * Helper expansion phases * Fix formatting
1 parent 4ead807 commit 53b4cd0

File tree

13 files changed

+945
-675
lines changed

13 files changed

+945
-675
lines changed

src/coreclr/jit/compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,6 +5031,8 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
50315031
optLoopTableValid = false;
50325032
optLoopsRequirePreHeaders = false;
50335033

5034+
DoPhase(this, PHASE_RATIONALIZE_ASSIGNMENTS, &Compiler::fgRationalizeAssignments);
5035+
50345036
#ifdef DEBUG
50355037
DoPhase(this, PHASE_STRESS_SPLIT_TREE, &Compiler::StressSplitTree);
50365038
#endif
@@ -5069,8 +5071,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
50695071
//
50705072
DoPhase(this, PHASE_DETERMINE_FIRST_COLD_BLOCK, &Compiler::fgDetermineFirstColdBlock);
50715073

5072-
DoPhase(this, PHASE_RATIONALIZE_ASSIGNMENTS, &Compiler::fgRationalizeAssignments);
5073-
50745074
#ifdef DEBUG
50755075
// Stash the current estimate of the function's size if necessary.
50765076
if (verbose)

src/coreclr/jit/compiler.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,7 @@ class Compiler
25362536
void* compileTimeHandle);
25372537

25382538
GenTreeLclVar* gtNewLclvNode(unsigned lnum, var_types type DEBUGARG(IL_OFFSET offs = BAD_IL_OFFSET));
2539+
GenTreeLclVar* gtNewLclVarNode(unsigned lclNum, var_types type = TYP_UNDEF);
25392540
GenTreeLclVar* gtNewLclLNode(unsigned lnum, var_types type DEBUGARG(IL_OFFSET offs = BAD_IL_OFFSET));
25402541

25412542
GenTreeLclFld* gtNewLclVarAddrNode(unsigned lclNum, var_types type = TYP_I_IMPL);
@@ -2838,6 +2839,12 @@ class Compiler
28382839

28392840
GenTreeIndir* gtNewIndir(var_types typ, GenTree* addr, GenTreeFlags indirFlags = GTF_EMPTY);
28402841

2842+
GenTreeBlk* gtNewStoreBlkNode(
2843+
ClassLayout* layout, GenTree* addr, GenTree* data, GenTreeFlags indirFlags = GTF_EMPTY);
2844+
2845+
GenTreeStoreInd* gtNewStoreIndNode(
2846+
var_types type, GenTree* addr, GenTree* data, GenTreeFlags indirFlags = GTF_EMPTY);
2847+
28412848
GenTree* gtNewLoadValueNode(
28422849
var_types type, ClassLayout* layout, GenTree* addr, GenTreeFlags indirFlags = GTF_EMPTY);
28432850

@@ -2851,6 +2858,14 @@ class Compiler
28512858
return gtNewLoadValueNode(type, nullptr, addr, indirFlags);
28522859
}
28532860

2861+
GenTree* gtNewStoreValueNode(
2862+
var_types type, ClassLayout* layout, GenTree* addr, GenTree* data, GenTreeFlags indirFlags = GTF_EMPTY);
2863+
2864+
GenTree* gtNewStoreValueNode(ClassLayout* layout, GenTree* addr, GenTree* data, GenTreeFlags indirFlags = GTF_EMPTY)
2865+
{
2866+
return gtNewStoreValueNode(layout->GetType(), layout, addr, data, indirFlags);
2867+
}
2868+
28542869
GenTree* gtNewNullCheck(GenTree* addr, BasicBlock* basicBlock);
28552870

28562871
var_types gtTypeForNullCheck(GenTree* tree);
@@ -2962,6 +2977,9 @@ class Compiler
29622977

29632978
void gtPrepareCost(GenTree* tree);
29642979
bool gtIsLikelyRegVar(GenTree* tree);
2980+
void gtGetLclVarNodeCost(GenTreeLclVar* node, int* pCostEx, int* pCostSz, bool isLikelyRegVar);
2981+
void gtGetLclFldNodeCost(GenTreeLclFld* node, int* pCostEx, int* pCostSz);
2982+
bool gtGetIndNodeCost(GenTreeIndir* node, int* pCostEx, int* pCostSz);
29652983

29662984
// Returns true iff the secondNode can be swapped with firstNode.
29672985
bool gtCanSwapOrder(GenTree* firstNode, GenTree* secondNode);

src/coreclr/jit/compiler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ inline void GenTree::SetOper(genTreeOps oper, ValueNumberUpdate vnUpdate)
12301230
break;
12311231
#endif
12321232
case GT_LCL_FLD:
1233+
case GT_STORE_LCL_FLD:
12331234
AsLclFld()->SetLclOffs(0);
12341235
AsLclFld()->SetLayout(nullptr);
12351236
break;

src/coreclr/jit/decomposelongs.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,8 @@ GenTree* DecomposeLongs::DecomposeStoreLclFld(LIR::Use& use)
514514
loStore->gtFlags |= GTF_VAR_USEASG;
515515

516516
// Create the store for the upper half of the GT_LONG and insert it after the low store.
517-
GenTreeLclFld* hiStore = m_compiler->gtNewLclFldNode(loStore->GetLclNum(), TYP_INT, loStore->GetLclOffs() + 4);
518-
hiStore->SetOper(GT_STORE_LCL_FLD);
519-
hiStore->gtOp1 = value->gtOp2;
520-
hiStore->gtFlags |= (GTF_VAR_DEF | GTF_VAR_USEASG);
517+
GenTreeLclFld* hiStore =
518+
m_compiler->gtNewStoreLclFldNode(loStore->GetLclNum(), TYP_INT, loStore->GetLclOffs() + 4, value->gtOp2);
521519

522520
Range().InsertAfter(loStore, hiStore);
523521

src/coreclr/jit/fgopt.cpp

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,24 +3445,14 @@ bool Compiler::fgBlockEndFavorsTailDuplication(BasicBlock* block, unsigned lclNu
34453445
while (count < limit)
34463446
{
34473447
count++;
3448+
unsigned storeLclNum;
34483449
GenTree* const tree = stmt->GetRootNode();
3449-
if (tree->OperIs(GT_ASG) && !tree->OperIsBlkOp())
3450+
if (tree->OperIsStoreLcl(&storeLclNum) && (storeLclNum == lclNum) && !tree->OperIsBlkOp())
34503451
{
3451-
GenTree* const op1 = tree->AsOp()->gtOp1;
3452-
3453-
if (op1->IsLocal())
3452+
GenTree* const data = tree->Data();
3453+
if (data->OperIsArrLength() || data->OperIsConst() || data->OperIsCompare())
34543454
{
3455-
const unsigned op1LclNum = op1->AsLclVarCommon()->GetLclNum();
3456-
3457-
if (op1LclNum == lclNum)
3458-
{
3459-
GenTree* const op2 = tree->AsOp()->gtOp2;
3460-
3461-
if (op2->OperIsArrLength() || op2->OperIsConst() || op2->OperIsCompare())
3462-
{
3463-
return true;
3464-
}
3465-
}
3455+
return true;
34663456
}
34673457
}
34683458

@@ -3616,36 +3606,29 @@ bool Compiler::fgBlockIsGoodTailDuplicationCandidate(BasicBlock* target, unsigne
36163606
// Otherwise check the first stmt.
36173607
// Verify the branch is just a simple local compare.
36183608
//
3609+
unsigned storeLclNum;
36193610
GenTree* const firstTree = firstStmt->GetRootNode();
3620-
3621-
if (firstTree->gtOper != GT_ASG)
3622-
{
3623-
return false;
3624-
}
3625-
3626-
GenTree* const lhs = firstTree->AsOp()->gtOp1;
3627-
if (!lhs->OperIs(GT_LCL_VAR))
3611+
if (!firstTree->OperIsStoreLclVar(&storeLclNum))
36283612
{
36293613
return false;
36303614
}
36313615

3632-
const unsigned lhsLcl = lhs->AsLclVarCommon()->GetLclNum();
3633-
if (lhsLcl != *lclNum)
3616+
if (storeLclNum != *lclNum)
36343617
{
36353618
return false;
36363619
}
36373620

36383621
// Could allow unary here too...
36393622
//
3640-
GenTree* const rhs = firstTree->AsOp()->gtOp2;
3641-
if (!rhs->OperIsBinary())
3623+
GenTree* const data = firstTree->Data();
3624+
if (!data->OperIsBinary())
36423625
{
36433626
return false;
36443627
}
36453628

36463629
// op1 must be some combinations of casts of local or constant
36473630
// (or unary)
3648-
op1 = rhs->AsOp()->gtOp1;
3631+
op1 = data->AsOp()->gtOp1;
36493632
while (op1->gtOper == GT_CAST)
36503633
{
36513634
op1 = op1->AsOp()->gtOp1;
@@ -3658,7 +3641,7 @@ bool Compiler::fgBlockIsGoodTailDuplicationCandidate(BasicBlock* target, unsigne
36583641

36593642
// op2 must be some combinations of casts of local or constant
36603643
// (or unary)
3661-
op2 = rhs->AsOp()->gtOp2;
3644+
op2 = data->AsOp()->gtOp2;
36623645

36633646
// A binop may not actually have an op2.
36643647
//

src/coreclr/jit/flowgraph.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,6 +2979,7 @@ GenTree* Compiler::fgRationalizeAssignment(GenTreeOp* assignment)
29792979
{
29802980
store->SetReverseOp();
29812981
}
2982+
store->CopyRawCosts(assignment);
29822983

29832984
if (storeOp == GT_STOREIND)
29842985
{

0 commit comments

Comments
 (0)