Skip to content
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

Add missing logging to gtFoldExpr #47757

Merged
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
167 changes: 70 additions & 97 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4716,13 +4716,9 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
break;

default:
#ifdef DEBUG
if (verbose)
{
printf("unexpected operator in this tree:\n");
gtDispTree(tree);
}
#endif
JITDUMP("unexpected operator in this tree:\n");
DISPTREE(tree);

NO_WAY("unexpected operator");
}

Expand Down Expand Up @@ -12496,27 +12492,33 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree)
fgWalkTreePre(&colon_op2, gtClearColonCond);
}

JITDUMP("\nIdentical GT_COLON trees! ");
DISPTREE(op2);

GenTree* op;
if (sideEffList == nullptr)
{
// No side-effects, just return colon_op2
return colon_op2;
JITDUMP("No side effects, bashing to second operand:\n");
op = colon_op2;
}
else
{
#ifdef DEBUG
if (verbose)
{
printf("\nIdentical GT_COLON trees with side effects! Extracting side effects...\n");
gtDispTree(sideEffList);
printf("\n");
}
#endif
JITDUMP("Extracting side effects...\n");
DISPTREE(sideEffList);

// Change the GT_COLON into a GT_COMMA node with the side-effects
op2->ChangeOper(GT_COMMA);
op2->gtFlags |= (sideEffList->gtFlags & GTF_ALL_EFFECT);
op2->AsOp()->gtOp1 = sideEffList;
return op2;

JITDUMP("Transformed GT_COLON into GT_COMMA:\n");
op = op2;
}

DISPTREE(op);

return op;
}
}
}
Expand Down Expand Up @@ -12691,6 +12693,9 @@ GenTree* Compiler::gtFoldExprCompare(GenTree* tree)

/* The node has beeen folded into 'cons' */

JITDUMP("\nFolding comparison with identical operands:\n");
DISPTREE(tree);

if (fgGlobalMorph)
{
fgMorphTreeDone(cons);
Expand All @@ -12701,6 +12706,9 @@ GenTree* Compiler::gtFoldExprCompare(GenTree* tree)
cons->gtPrev = tree->gtPrev;
}

JITDUMP("Bashed to %s:\n", cons->AsIntConCommon()->IconValue() ? "true" : "false");
DISPTREE(cons);

return cons;
}

Expand Down Expand Up @@ -13133,31 +13141,35 @@ GenTree* Compiler::gtFoldExprSpecial(GenTree* tree)
if (tree->IsUnsigned() && (val == 0) && (op1 == cons) && !opHasSideEffects)
{
// unsigned (0 <= x) is always true
return NewMorphedIntConNode(1);
op = NewMorphedIntConNode(1);
goto DONE_FOLD;
}
break;

case GT_GE:
if (tree->IsUnsigned() && (val == 0) && (op2 == cons) && !opHasSideEffects)
{
// unsigned (x >= 0) is always true
return NewMorphedIntConNode(1);
op = NewMorphedIntConNode(1);
goto DONE_FOLD;
}
break;

case GT_LT:
if (tree->IsUnsigned() && (val == 0) && (op2 == cons) && !opHasSideEffects)
{
// unsigned (x < 0) is always false
return NewMorphedIntConNode(0);
op = NewMorphedIntConNode(0);
goto DONE_FOLD;
}
break;

case GT_GT:
if (tree->IsUnsigned() && (val == 0) && (op1 == cons) && !opHasSideEffects)
{
// unsigned (0 > x) is always false
return NewMorphedIntConNode(0);
op = NewMorphedIntConNode(0);
goto DONE_FOLD;
}
FALLTHROUGH;
case GT_EQ:
Expand Down Expand Up @@ -13382,6 +13394,11 @@ GenTree* Compiler::gtFoldExprSpecial(GenTree* tree)
op->gtFlags &= ~(GTF_VAR_USEASG | GTF_VAR_DEF);
}

JITDUMP("\nFolding binary operator with a constant operand:\n");
DISPTREE(tree);
JITDUMP("Transformed into:\n");
DISPTREE(op);

return op;
}

Expand Down Expand Up @@ -14475,13 +14492,9 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
// We only fold a GT_ADD that involves a null reference.
if (((op1->TypeGet() == TYP_REF) && (i1 == 0)) || ((op2->TypeGet() == TYP_REF) && (i2 == 0)))
{
#ifdef DEBUG
if (verbose)
{
printf("\nFolding operator with constant nodes into a constant:\n");
gtDispTree(tree);
}
#endif
JITDUMP("\nFolding operator with constant nodes into a constant:\n");
DISPTREE(tree);

// Fold into GT_IND of null byref
tree->ChangeOperConst(GT_CNS_INT);
tree->gtType = TYP_BYREF;
Expand All @@ -14491,13 +14504,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
{
fgValueNumberTreeConst(tree);
}
#ifdef DEBUG
if (verbose)
{
printf("\nFolded to null byref:\n");
gtDispTree(tree);
}
#endif

JITDUMP("\nFolded to null byref:\n");
DISPTREE(tree);

goto DONE;
}
break;
Expand Down Expand Up @@ -14746,13 +14756,8 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
CNS_INT:
FOLD_COND:

#ifdef DEBUG
if (verbose)
{
printf("\nFolding operator with constant nodes into a constant:\n");
gtDispTree(tree);
}
#endif
JITDUMP("\nFolding operator with constant nodes into a constant:\n");
DISPTREE(tree);

#ifdef TARGET_64BIT
// Some operations are performed as 64 bit instead of 32 bit so the upper 32 bits
Expand All @@ -14772,13 +14777,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
{
fgValueNumberTreeConst(tree);
}
#ifdef DEBUG
if (verbose)
{
printf("Bashed to int constant:\n");
gtDispTree(tree);
}
#endif

JITDUMP("Bashed to int constant:\n");
DISPTREE(tree);

goto DONE;

/* This operation is going to cause an overflow exception. Morph into
Expand All @@ -14804,7 +14806,6 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
// for global morphing phase.
//
// TODO-CQ: Once fgMorphArgs() is fixed this restriction could be removed.
CLANG_FORMAT_COMMENT_ANCHOR;

if (!fgGlobalMorph)
{
Expand Down Expand Up @@ -14846,13 +14847,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
goto OVF;

OVF:
#ifdef DEBUG
if (verbose)
{
printf("\nFolding binary operator with constant nodes into a comma throw:\n");
gtDispTree(tree);
}
#endif

JITDUMP("\nFolding binary operator with constant nodes into a comma throw:\n");
DISPTREE(tree);

/* We will change the cast to a GT_COMMA and attach the exception helper as AsOp()->gtOp1.
* The constant expression zero becomes op2. */

Expand Down Expand Up @@ -15166,13 +15164,9 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
return tree;
}

#ifdef DEBUG
if (verbose)
{
printf("\nFolding long operator with constant nodes into a constant:\n");
gtDispTree(tree);
}
#endif
JITDUMP("\nFolding long operator with constant nodes into a constant:\n");
DISPTREE(tree);

assert((GenTree::s_gtNodeSizes[GT_CNS_NATIVELONG] == TREE_NODE_SZ_SMALL) ||
(tree->gtDebugFlags & GTF_DEBUG_NODE_LARGE));

Expand All @@ -15183,13 +15177,9 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
fgValueNumberTreeConst(tree);
}

#ifdef DEBUG
if (verbose)
{
printf("Bashed to long constant:\n");
gtDispTree(tree);
}
#endif
JITDUMP("Bashed to long constant:\n");
DISPTREE(tree);

goto DONE;

/*-------------------------------------------------------------------------
Expand Down Expand Up @@ -15218,12 +15208,8 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)

if (_isnan(d1) || _isnan(d2))
{
#ifdef DEBUG
if (verbose)
{
printf("Double operator(s) is NaN\n");
}
#endif
JITDUMP("Double operator(s) is NaN\n");

if (tree->OperKind() & GTK_RELOP)
{
if (tree->gtFlags & GTF_RELOP_NAN_UN)
Expand Down Expand Up @@ -15337,13 +15323,8 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)

CNS_DOUBLE:

#ifdef DEBUG
if (verbose)
{
printf("\nFolding fp operator with constant nodes into a fp constant:\n");
gtDispTree(tree);
}
#endif
JITDUMP("\nFolding fp operator with constant nodes into a fp constant:\n");
DISPTREE(tree);

assert((GenTree::s_gtNodeSizes[GT_CNS_DBL] == TREE_NODE_SZ_SMALL) ||
(tree->gtDebugFlags & GTF_DEBUG_NODE_LARGE));
Expand All @@ -15354,13 +15335,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
{
fgValueNumberTreeConst(tree);
}
#ifdef DEBUG
if (verbose)
{
printf("Bashed to fp constant:\n");
gtDispTree(tree);
}
#endif

JITDUMP("Bashed to fp constant:\n");
DISPTREE(tree);

goto DONE;

default:
Expand Down Expand Up @@ -15976,12 +15954,7 @@ void Compiler::gtExtractSideEffList(GenTree* expr,
if (node->OperIs(GT_ADDR) && node->gtGetOp1()->OperIsIndir() &&
(node->gtGetOp1()->TypeGet() == TYP_STRUCT))
{
#ifdef DEBUG
if (m_compiler->verbose)
{
printf("Keep the GT_ADDR and GT_IND together:\n");
}
#endif
JITDUMP("Keep the GT_ADDR and GT_IND together:\n");
m_sideEffects.Push(node);
return Compiler::WALK_SKIP_SUBTREES;
}
Expand Down