Skip to content

JIT: allow forward sub of QMARK nodes #76476

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

Merged
merged 1 commit into from
Oct 1, 2022
Merged
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
42 changes: 36 additions & 6 deletions src/coreclr/jit/forwardsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,13 @@ bool Compiler::fgForwardSubStatement(Statement* stmt)
GenTree* const rhsNode = rootNode->gtGetOp2();
GenTree* fwdSubNode = rhsNode;

// Can't substitute a qmark (unless the use is RHS of an assign... could check for this)
// Can't substitute GT_CATCH_ARG.
// Can't substitute GT_LCLHEAP.
//
// Don't substitute a no return call (trips up morph in some cases).
//
if (fwdSubNode->OperIs(GT_QMARK, GT_CATCH_ARG, GT_LCLHEAP))
if (fwdSubNode->OperIs(GT_CATCH_ARG, GT_LCLHEAP))
{
JITDUMP(" tree to sub is qmark, catch arg, or lcl heap\n");
JITDUMP(" tree to sub is catch arg, or lcl heap\n");
return false;
}

Expand Down Expand Up @@ -511,6 +509,40 @@ bool Compiler::fgForwardSubStatement(Statement* stmt)

JITDUMP(" [%06u] is only use of [%06u] (V%02u) ", dspTreeID(fsv.GetNode()), dspTreeID(lhsNode), lclNum);

// Qmarks must replace top-level uses. Also, restrict to GT_ASG.
// And also to where neither local is normalize on store, otherwise
// something downstream may add a cast over the qmark.
//
GenTree* const nextRootNode = nextStmt->GetRootNode();
if (fwdSubNode->OperIs(GT_QMARK))
{
if ((fsv.GetParentNode() != nextRootNode) || !nextRootNode->OperIs(GT_ASG))
{
JITDUMP(" can't fwd sub qmark as use is not top level ASG\n");
return false;
}

if (varDsc->lvNormalizeOnStore())
{
JITDUMP(" can't fwd sub qmark as V%02u is normalize on store\n", lclNum);
return false;
}

GenTree* const nextRootNodeLHS = nextRootNode->gtGetOp1();

if (nextRootNodeLHS->OperIs(GT_LCL_VAR))
{
const unsigned lhsLclNum = nextRootNodeLHS->AsLclVarCommon()->GetLclNum();
LclVarDsc* const lhsVarDsc = lvaGetDesc(lhsLclNum);

if (lhsVarDsc->lvNormalizeOnStore())
{
JITDUMP(" can't fwd sub qmark as V%02u is normalize on store\n", lhsLclNum);
return false;
}
}
}

// If next statement already has a large tree, hold off
// on making it even larger.
//
Expand All @@ -527,8 +559,6 @@ bool Compiler::fgForwardSubStatement(Statement* stmt)
// Next statement seems suitable.
// See if we can forward sub without changing semantics.
//
GenTree* const nextRootNode = nextStmt->GetRootNode();

// Bail if types disagree.
// Might be able to tolerate these by retyping.
//
Expand Down