Skip to content

Commit

Permalink
Call gtFoldExpr in morph for tier0 (#105190)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Jul 22, 2024
1 parent 7c3286f commit 27f52d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13402,9 +13402,15 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree)
}
else if (op1->OperIsConst() || op2->OperIsConst())
{
/* at least one is a constant - see if we have a
* special operator that can use only one constant
* to fold - e.g. booleans */
// At least one is a constant - see if we have a
// special operator that can use only one constant
// to fold - e.g. booleans

if (tier0opts && opts.OptimizationDisabled())
{
// Too heavy for tier0
return tree;
}

return gtFoldExprSpecial(tree);
}
Expand Down
19 changes: 5 additions & 14 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8028,10 +8028,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA

GenTree* oldTree = tree;

if (opts.OptimizationEnabled())
{
tree = gtFoldExpr(tree);
}
tree = gtFoldExpr(tree);

// Were we able to fold it ?
// Note that gtFoldExpr may return a non-leaf even if successful
Expand Down Expand Up @@ -8330,11 +8327,8 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
qmarkOp2 = oldTree->AsOp()->gtOp2->AsOp()->gtOp2;
}

if (opts.OptimizationEnabled())
{
// Try to fold it, maybe we get lucky,
tree = gtFoldExpr(tree);
}
// Try to fold it, maybe we get lucky,
tree = gtFoldExpr(tree);

if (oldTree != tree)
{
Expand Down Expand Up @@ -12360,11 +12354,8 @@ GenTree* Compiler::fgMorphTree(GenTree* tree, MorphAddrContext* mac)
tree->gtFlags |= tree->AsConditional()->gtOp1->gtFlags & GTF_ALL_EFFECT;
tree->gtFlags |= tree->AsConditional()->gtOp2->gtFlags & GTF_ALL_EFFECT;

if (opts.OptimizationEnabled())
{
// Try to fold away any constants etc.
tree = gtFoldExpr(tree);
}
// Try to fold away any constants etc.
tree = gtFoldExpr(tree);

break;

Expand Down

0 comments on commit 27f52d9

Please sign in to comment.