Skip to content

Commit 02e657e

Browse files
authored
Merge pull request dotnet#11 from pgavlin/LIRFixes
Fix a few bugs/diffs in the LIR backend.
2 parents 4447d5a + 20eeaf4 commit 02e657e

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

src/jit/lir.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,26 @@ GenTree* LIR::Range::FirstNonPhiNode() const
506506
{
507507
assert(IsValid());
508508

509-
for (GenTree* node : *this)
509+
GenTree* node, *end;
510+
for (node = Begin(), end = End(); node != end; node = node->gtNext)
510511
{
511-
if ((node->OperGet() != GT_PHI_ARG) && (node->OperGet() != GT_PHI) && !node->IsPhiDefn())
512+
if (node->OperGet() == GT_PHI_ARG)
512513
{
513-
return node;
514+
continue;
514515
}
516+
else if (node->OperGet() == GT_PHI)
517+
{
518+
continue;
519+
}
520+
else if (node->IsPhiDefn())
521+
{
522+
continue;
523+
}
524+
525+
break;
515526
}
516527

517-
return End();
528+
return node;
518529
}
519530

520531
//------------------------------------------------------------------------
@@ -526,15 +537,22 @@ GenTree* LIR::Range::FirstNonPhiOrCatchArgNode() const
526537
{
527538
assert(IsValid());
528539

529-
for (GenTree* node = FirstNonPhiNode(), *end = End(); node != end; node = node->gtNext)
540+
GenTree* node, *end;
541+
for (node = FirstNonPhiNode(), end = End(); node != end; node = node->gtNext)
530542
{
531-
if ((node->OperGet() == GT_STORE_LCL_VAR) && (node->gtOp.gtOp1->OperGet() == GT_CATCH_ARG))
543+
if (node->OperGet() == GT_CATCH_ARG)
532544
{
533-
return node->gtNext;
545+
continue;
534546
}
547+
else if ((node->OperGet() == GT_STORE_LCL_VAR) && (node->gtGetOp1()->OperGet() == GT_CATCH_ARG))
548+
{
549+
continue;
550+
}
551+
552+
break;
535553
}
536554

537-
return End();
555+
return node;
538556
}
539557

540558
//------------------------------------------------------------------------
@@ -1091,6 +1109,8 @@ bool LIR::Range::CheckLIR(Compiler* compiler, bool checkUnusedValues) const
10911109
// Verify that the node is allowed in LIR.
10921110
assert(node->IsLIR());
10931111

1112+
// TODO: validate catch arg stores
1113+
10941114
// Check that all phi nodes (if any) occur at the start of the range.
10951115
if ((node->OperGet() == GT_PHI_ARG) || (node->OperGet() == GT_PHI) || node->IsPhiDefn())
10961116
{

src/jit/lower.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,8 +2330,7 @@ void Lowering::InsertPInvokeMethodProlog()
23302330
}
23312331

23322332
comp->fgMorphTree(store);
2333-
firstBlockRange.InsertAfter(LIR::SeqTree(comp, store), insertionPoint);
2334-
insertionPoint = store;
2333+
firstBlockRange.InsertBefore(LIR::SeqTree(comp, store), insertionPoint);
23352334

23362335
DISPTREE(store);
23372336

@@ -2345,8 +2344,7 @@ void Lowering::InsertPInvokeMethodProlog()
23452344
callFrameInfo.offsetOfCallSiteSP);
23462345
storeSP->gtOp1 = PhysReg(REG_SPBASE);
23472346

2348-
firstBlockRange.InsertAfter(LIR::SeqTree(comp, storeSP), insertionPoint);
2349-
insertionPoint = storeSP;
2347+
firstBlockRange.InsertBefore(LIR::SeqTree(comp, storeSP), insertionPoint);
23502348

23512349
DISPTREE(storeSP);
23522350

@@ -2360,8 +2358,7 @@ void Lowering::InsertPInvokeMethodProlog()
23602358
callFrameInfo.offsetOfCalleeSavedFP);
23612359
storeFP->gtOp1 = PhysReg(REG_FPBASE);
23622360

2363-
firstBlockRange.InsertAfter(LIR::SeqTree(comp, storeFP), insertionPoint);
2364-
insertionPoint = storeFP;
2361+
firstBlockRange.InsertBefore(LIR::SeqTree(comp, storeFP), insertionPoint);
23652362

23662363
DISPTREE(storeFP);
23672364

@@ -2372,7 +2369,7 @@ void Lowering::InsertPInvokeMethodProlog()
23722369
// Push a frame - if we are NOT in an IL stub, this is done right before the call
23732370
// The init routine sets InlinedCallFrame's m_pNext, so we just set the thead's top-of-stack
23742371
GenTree* frameUpd = CreateFrameLinkUpdate(PushFrame);
2375-
firstBlockRange.InsertAfter(LIR::SeqTree(comp, frameUpd), insertionPoint);
2372+
firstBlockRange.InsertBefore(LIR::SeqTree(comp, frameUpd), insertionPoint);
23762373
DISPTREE(frameUpd);
23772374
}
23782375
}

src/jit/rationalize.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,6 @@ Compiler::fgWalkResult Rationalizer::RewriteNode(GenTree** useEdge, ArrayStack<G
13561356
#endif // FEATURE_SIMD
13571357

13581358
default:
1359-
// Ensure that the LIR flags are clear.
1360-
node->gtLIRFlags = LIR::Flags::None;
13611359
break;
13621360
}
13631361

@@ -1392,6 +1390,9 @@ void Rationalizer::DoPhase()
13921390
// This needs to be done before the transition to LIR because it relies on the use
13931391
// of fgMorphArgs, which is designed to operate on HIR. Once this is done for a
13941392
// particular statement, link that statement's nodes into the current basic block.
1393+
//
1394+
// This walk also clears the GTF_VAR_USEDEF bit on locals, which is not necessary
1395+
// in the backend.
13951396
GenTree* lastNodeInPreviousStatement = nullptr;
13961397
for (GenTreeStmt* statement = firstStatement; statement != nullptr; statement = statement->getNextStmt())
13971398
{
@@ -1414,6 +1415,10 @@ void Rationalizer::DoPhase()
14141415

14151416
walkData->compiler->fgFixupIfCallArg(walkData->parentStack, node, *use);
14161417
}
1418+
else if (node->OperIsLocal())
1419+
{
1420+
node->gtFlags &= ~GTF_VAR_USEDEF;
1421+
}
14171422

14181423
return Compiler::WALK_CONTINUE;
14191424
},

0 commit comments

Comments
 (0)