Skip to content
Closed
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: 9 additions & 15 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16571,7 +16571,9 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
// update args table. For this reason this optimization is enabled only
// for global morphing phase.
//
// TODO-CQ: Once fgMorphArgs() is fixed this restriction could be removed.
// TODO-CQ: Once fgMorphArgs() is fixed this restriction could be removed,
// but it would require to know whether or not we are after morph such that
// we know when the call created below needs to be in morphed form.

if (!fgGlobalMorph)
{
Expand All @@ -16581,10 +16583,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)

var_types type = genActualType(tree->TypeGet());
op1 = type == TYP_LONG ? gtNewLconNode(0) : gtNewIconNode(0);
if (vnStore != nullptr)
{
op1->gtVNPair.SetBoth(vnStore->VNZeroForType(type));
}
INDEBUG(op1->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);

// Would need to set VNs if this wasn't in global morph only.
assert(vnStore == nullptr);

JITDUMP("\nFolding binary operator with constant nodes into a comma throw:\n");
DISPTREE(tree);
Expand All @@ -16598,18 +16600,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)

op2 = op1;
op1 = gtNewHelperCallNode(CORINFO_HELP_OVERFLOW, TYP_VOID, gtNewIconNode(compCurBB->bbTryIndex));

// op1 is a call to the JIT helper that throws an Overflow exception.
// Attach the ExcSet for VNF_OverflowExc(Void) to this call.

if (vnStore != nullptr)
{
op1->gtVNPair = vnStore->VNPWithExc(ValueNumPair(ValueNumStore::VNForVoid(), ValueNumStore::VNForVoid()),
vnStore->VNPExcSetSingleton(vnStore->VNPairForFunc(TYP_REF, VNF_OverflowExc,
vnStore->VNPForVoid())));
}
op1 = fgMorphTree(op1);

tree = gtNewOperNode(GT_COMMA, tree->TypeGet(), op1, op2);
INDEBUG(tree->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);

return tree;
}
Expand Down
24 changes: 1 addition & 23 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8307,29 +8307,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
// Try to fold it, maybe we get lucky,
tree = gtFoldExpr(tree);

if (oldTree != tree)
{
/* if gtFoldExpr returned op1 or op2 then we are done */
if ((tree == op1) || (tree == op2) || (tree == qmarkOp1) || (tree == qmarkOp2))
{
return tree;
}

/* If we created a comma-throw tree then we need to morph op1 */
if (fgIsCommaThrow(tree))
{
tree->AsOp()->gtOp1 = fgMorphTree(tree->AsOp()->gtOp1);
fgMorphTreeDone(tree);
return tree;
}

return tree;
}
else if (tree->OperIsConst())
{
return tree;
}
else if (tree->IsNothingNode())
if ((oldTree != tree) || tree->OperIsConst() || tree->IsNothingNode())
{
return tree;
}
Expand Down
Loading