diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp index 54c1a3b26848..28855986baa6 100644 --- a/src/coreclr/jit/fgprofile.cpp +++ b/src/coreclr/jit/fgprofile.cpp @@ -1448,34 +1448,12 @@ void EfficientEdgeCountInstrumentor::SplitCriticalEdges() JITDUMP("Could not find " FMT_BB " -> " FMT_BB " edge to instrument\n", block->bbNum, target->bbNum); - // If we're optimizing, assume this edge got folded away - // - if (m_comp->opts.IsInstrumentedOptimized()) - { - JITDUMP(" -- assuming this edge was folded away by the importer\n"); + JITDUMP(" -- assuming this edge was folded away by the importer\n"); - // Placate the asserts below - // - instrumentedBlock = source; - edgesIgnored++; - } - // If the source block is a partial compilation patchpoint - // then the edge will have been removed. + // Placate the asserts below // - else if ((block->bbFlags & BBF_PARTIAL_COMPILATION_PATCHPOINT) == - BBF_PARTIAL_COMPILATION_PATCHPOINT) - { - JITDUMP(" -- source block is partial compilation patchpoint\n"); - - // Placate the asserts below - // - instrumentedBlock = source; - edgesIgnored++; - } - else - { - assert(found); - } + instrumentedBlock = source; + edgesIgnored++; } // Delete the critical edge probe diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 16fe9b2f19cc..9901718bdb68 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -6085,9 +6085,6 @@ unsigned GenTree::GetScaleIndexShf() unsigned GenTree::GetScaledIndex() { - // with (!opts.OptEnabled(CLFLG_CONSTANTFOLD) we can have - // CNS_INT * CNS_INT - // if (AsOp()->gtOp1->IsCnsIntOrI()) { return 0; @@ -12853,6 +12850,14 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree) return tree; } + // NOTE: MinOpts() is always true for Tier0 so we have to check explicit flags instead. + // To be fixed in https://github.com/dotnet/runtime/pull/77465 + const bool tier0opts = !opts.compDbgCode && !opts.jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT); + if (!tier0opts) + { + return tree; + } + if (!(kind & GTK_SMPOP)) { if (tree->OperIsConditional()) @@ -12886,9 +12891,7 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree) return gtFoldExprConst(tree); } } - else if ((kind & GTK_BINOP) && op1 && tree->AsOp()->gtOp2 && - // Don't take out conditionals for debugging - (opts.OptimizationEnabled() || !tree->OperIsCompare())) + else if ((kind & GTK_BINOP) && op1 && tree->AsOp()->gtOp2) { GenTree* op2 = tree->AsOp()->gtOp2; @@ -14552,7 +14555,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree) GenTree* op1 = tree->gtGetOp1(); GenTree* op2 = tree->gtGetOp2IfPresent(); - if (!opts.OptEnabled(CLFLG_CONSTANTFOLD)) + // NOTE: MinOpts() is always true for Tier0 so we have to check explicit flags instead. + // To be fixed in https://github.com/dotnet/runtime/pull/77465 + const bool tier0opts = !opts.compDbgCode && !opts.jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT); + if (!tier0opts) { return tree; } diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index d30384982965..a772bbe771af 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -8232,7 +8232,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) op1->gtFlags |= (GTF_OVERFLOW | GTF_EXCEPT); } - if (op1->gtGetOp1()->OperIsConst() && opts.OptimizationEnabled()) + if (op1->gtGetOp1()->OperIsConst()) { // Try and fold the introduced cast op1 = gtFoldExprConst(op1); diff --git a/src/coreclr/jit/jit.h b/src/coreclr/jit/jit.h index eef88bee6c97..84fc4602aaa1 100644 --- a/src/coreclr/jit/jit.h +++ b/src/coreclr/jit/jit.h @@ -701,7 +701,6 @@ class Histogram #define CLFLG_QMARK 0x00080 #define CLFLG_TREETRANS 0x00100 #define CLFLG_INLINING 0x00200 -#define CLFLG_CONSTANTFOLD 0x00800 #if FEATURE_STRUCTPROMOTE #define CLFLG_STRUCTPROMOTE 0x00400 @@ -717,7 +716,7 @@ class Histogram #define CLFLG_MAXOPT \ (CLFLG_CSE | CLFLG_REGVAR | CLFLG_RNGCHKOPT | CLFLG_DEADASGN | CLFLG_CODEMOTION | CLFLG_QMARK | CLFLG_TREETRANS | \ - CLFLG_INLINING | CLFLG_STRUCTPROMOTE | CLFLG_CONSTANTFOLD) + CLFLG_INLINING | CLFLG_STRUCTPROMOTE) #define CLFLG_MINOPT (CLFLG_TREETRANS) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 15521b03761b..ca7909f75121 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -8404,6 +8404,11 @@ GenTreeOp* Compiler::fgMorphCommutative(GenTreeOp* tree) assert(varTypeIsIntegralOrI(tree->TypeGet())); assert(tree->OperIs(GT_ADD, GT_MUL, GT_OR, GT_AND, GT_XOR)); + if (opts.OptimizationDisabled()) + { + return nullptr; + } + // op1 can be GT_COMMA, in this case we're going to fold // "(op (COMMA(... (op X C1))) C2)" to "(COMMA(... (op X C3)))" GenTree* op1 = tree->gtGetOp1()->gtEffectiveVal(true); @@ -8836,7 +8841,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA // then don't morph to a helper call - it can be done faster inline using idiv. noway_assert(op2); - if ((typ == TYP_LONG) && opts.OptEnabled(CLFLG_CONSTANTFOLD)) + if ((typ == TYP_LONG) && opts.OptimizationEnabled()) { if (op2->OperIs(GT_CNS_NATIVELONG) && op2->AsIntConCommon()->LngValue() >= 2 && op2->AsIntConCommon()->LngValue() <= 0x3fffffff) @@ -8961,7 +8966,10 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA GenTree* oldTree = tree; - tree = gtFoldExpr(tree); + if (opts.OptimizationEnabled()) + { + tree = gtFoldExpr(tree); + } // Were we able to fold it ? // Note that gtFoldExpr may return a non-leaf even if successful @@ -9398,8 +9406,11 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA qmarkOp2 = oldTree->AsOp()->gtOp2->AsOp()->gtOp2; } - // Try to fold it, maybe we get lucky, - tree = gtFoldExpr(tree); + if (opts.OptimizationEnabled()) + { + // Try to fold it, maybe we get lucky, + tree = gtFoldExpr(tree); + } if (oldTree != tree) { @@ -9769,7 +9780,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA } /* Any constant cases should have been folded earlier */ - noway_assert(!op1->OperIsConst() || !opts.OptEnabled(CLFLG_CONSTANTFOLD) || optValnumCSE_phase); + noway_assert(!op1->OperIsConst() || opts.OptimizationDisabled() || optValnumCSE_phase); break; case GT_CKFINITE: @@ -12769,8 +12780,11 @@ 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; - // Try to fold away any constants etc. - tree = gtFoldExpr(tree); + if (opts.OptimizationEnabled()) + { + // Try to fold away any constants etc. + tree = gtFoldExpr(tree); + } break;