From 7abf507cb9330aa52b838641e9bf00a6e232609e Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 20 Jul 2024 21:24:05 +0200 Subject: [PATCH 1/2] Call gtFoldExpr in morph for tier0 --- src/coreclr/jit/morph.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 3b971780ff232e..0d922459acdc40 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -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 @@ -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) { @@ -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; From fcfa6ec25a616857c8103e19552e10ee4438e73f Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 21 Jul 2024 01:11:26 +0200 Subject: [PATCH 2/2] fix tp --- src/coreclr/jit/gentree.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 5e05856d8d9e6c..8ba61fe3a1121c 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -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); }