Skip to content

Commit

Permalink
Merge pull request #6 from jakobbotsch/stack-allocate-unescaped-boxes…
Browse files Browse the repository at this point in the history
…-lclmorph

Minor fixes
  • Loading branch information
AndyAyersMS authored Jun 12, 2024
2 parents 56500c3 + 67402d4 commit 5a08c84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/coreclr/jit/lclmorph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,34 +1033,30 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
assert(TopValue(1).Node() == node->AsOp()->gtOp1);
assert(TopValue(0).Node() == node->AsOp()->gtOp2);

GenTree* op1 = node->AsOp()->gtOp1;
GenTree* op2 = node->AsOp()->gtOp2;
bool rewrite = false;
Value& lhs = TopValue(1);
Value& rhs = TopValue(0);

if (op1->OperIs(GT_LCL_ADDR) && op2->IsIntegralConst(0))
if ((lhs.IsAddress() && rhs.Node()->IsIntegralConst(0)) ||
(rhs.IsAddress() && lhs.Node()->IsIntegralConst(0)))
{
op1 = m_compiler->gtNewIconNode(1);
op2->ChangeType(TYP_INT);
rewrite = true;
}
else if (op2->OperIs(GT_LCL_ADDR) && op1->IsIntegralConst(0))
{
op2 = m_compiler->gtNewIconNode(1);
op1->ChangeType(TYP_INT);
rewrite = true;
}
JITDUMP("Rewriting known address-of comparison [%06u]\n", m_compiler->dspTreeID(node));
*lhs.Use() = m_compiler->gtNewIconNode(0);
*rhs.Use() = m_compiler->gtNewIconNode(1);
m_stmtModified = true;

if (rewrite)
INDEBUG(TopValue(0).Consume());
INDEBUG(TopValue(1).Consume());
PopValue();
PopValue();
}
else
{
JITDUMP("Rewriting known address-of comparison [%06u]\n", m_compiler->dspTreeID(node));
node->AsOp()->gtOp1 = op1;
node->AsOp()->gtOp2 = op2;
EscapeValue(TopValue(0), node);
PopValue();
EscapeValue(TopValue(0), node);
PopValue();
}

INDEBUG(TopValue(0).Consume());
INDEBUG(TopValue(1).Consume());
PopValue();
PopValue();
break;
}

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2550,6 +2550,7 @@ bool Compiler::StructPromotionHelper::CanPromoteStructVar(unsigned lclNum)
if (varDsc->lvStackAllocatedBox)
{
JITDUMP(" struct promotion of V%02u is disabled because it is a stack allocated box\n", lclNum);
return false;
}

#ifdef SWIFT_SUPPORT
Expand Down

0 comments on commit 5a08c84

Please sign in to comment.