From 3dbc5031038eb30cce986bb0337895ce295fe47b Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Mon, 13 Nov 2023 18:08:36 -0800 Subject: [PATCH 1/5] JIT: enable cross-block local assertion prop --- src/coreclr/jit/jitconfigvalues.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/jitconfigvalues.h b/src/coreclr/jit/jitconfigvalues.h index 65afd348819e1..7627e26716bef 100644 --- a/src/coreclr/jit/jitconfigvalues.h +++ b/src/coreclr/jit/jitconfigvalues.h @@ -654,7 +654,7 @@ CONFIG_INTEGER(JitEnableHeadTailMerge, W("JitEnableHeadTailMerge"), 1) CONFIG_INTEGER(JitEnablePhysicalPromotion, W("JitEnablePhysicalPromotion"), 1) // Enable cross-block local assertion prop -CONFIG_INTEGER(JitEnableCrossBlockLocalAssertionProp, W("JitEnableCrossBlockLocalAssertionProp"), 0) +CONFIG_INTEGER(JitEnableCrossBlockLocalAssertionProp, W("JitEnableCrossBlockLocalAssertionProp"), 1) #if defined(DEBUG) // JitFunctionFile: Name of a file that contains a list of functions. If the currently compiled function is in the From 30c13fc2c1deb5d60b4c188526135185ec4e9734 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Wed, 15 Nov 2023 14:46:00 -0800 Subject: [PATCH 2/5] fix test case --- src/tests/JIT/Directed/debugging/debuginfo/tester.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/JIT/Directed/debugging/debuginfo/tester.csproj b/src/tests/JIT/Directed/debugging/debuginfo/tester.csproj index 360f004c1fd61..b343f6fffb597 100644 --- a/src/tests/JIT/Directed/debugging/debuginfo/tester.csproj +++ b/src/tests/JIT/Directed/debugging/debuginfo/tester.csproj @@ -13,6 +13,7 @@ + From bf43a278ea4bc0de8e942d4799178bbea218089d Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Thu, 16 Nov 2023 15:14:19 -0800 Subject: [PATCH 3/5] fix bug; add range enable --- src/coreclr/jit/assertionprop.cpp | 12 ++++++++++++ src/coreclr/jit/jitconfigvalues.h | 1 + src/coreclr/jit/morph.cpp | 14 ++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 8eacd46beee08..92ee287ea1f05 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -559,6 +559,18 @@ void Compiler::optAssertionInit(bool isLocalProp) optCrossBlockLocalAssertionProp = false; } +#ifdef DEBUG + // Disable per method via range + // + static ConfigMethodRange s_range; + s_range.EnsureInit(JitConfig.JitEnableCrossBlockLocalAssertionPropRange()); + if (!s_range.Contains(info.compMethodHash())) + { + JITDUMP("Disabling cross-block assertion prop by config range\n"); + optCrossBlockLocalAssertionProp = false; + } +#endif + // Disable if too many locals // // The typical number of local assertions is roughly proportional diff --git a/src/coreclr/jit/jitconfigvalues.h b/src/coreclr/jit/jitconfigvalues.h index 7627e26716bef..b4376d57d3a8d 100644 --- a/src/coreclr/jit/jitconfigvalues.h +++ b/src/coreclr/jit/jitconfigvalues.h @@ -460,6 +460,7 @@ CONFIG_STRING(JitEnableEarlyLivenessRange, W("JitEnableEarlyLivenessRange")) CONFIG_STRING(JitOnlyOptimizeRange, W("JitOnlyOptimizeRange")) // If set, all methods that do _not_ match are forced into MinOpts CONFIG_STRING(JitEnablePhysicalPromotionRange, W("JitEnablePhysicalPromotionRange")) +CONFIG_STRING(JitEnableCrossBlockLocalAssertionPropRange, W("JitEnableCrossBlockLocalAssertionPropRange")) CONFIG_INTEGER(JitDoSsa, W("JitDoSsa"), 1) // Perform Static Single Assignment (SSA) numbering on the variables CONFIG_INTEGER(JitDoValueNumber, W("JitDoValueNumber"), 1) // Perform value numbering on method expressions diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 1d8d532a437ad..391ca6758c55e 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -12940,12 +12940,13 @@ void Compiler::fgAssertionGen(GenTree* tree) // apLocal will be stored on bbAssertionOutIfFalse and be used for false successors. // apLocalIfTrue will be stored on bbAssertionOutIfTrue and be used for true successors. // - const bool doCondUpdates = tree->OperIs(GT_JTRUE) && compCurBB->KindIs(BBJ_COND) && (compCurBB->NumSucc() == 2); + const bool makeCondAssertions = + tree->OperIs(GT_JTRUE) && compCurBB->KindIs(BBJ_COND) && (compCurBB->NumSucc() == 2); // Intialize apLocalIfTrue if we might look for it later, // even if it ends up identical to apLocal. // - if (doCondUpdates) + if (makeCondAssertions) { apLocalIfTrue = BitVecOps::MakeCopy(apTraits, apLocal); } @@ -12957,7 +12958,7 @@ void Compiler::fgAssertionGen(GenTree* tree) AssertionInfo info = tree->GetAssertionInfo(); - if (doCondUpdates) + if (makeCondAssertions) { // Update apLocal and apIfTrue with suitable assertions // from the JTRUE @@ -13897,9 +13898,10 @@ void Compiler::fgMorphBlock(BasicBlock* block, unsigned highestReachablePostorde // Yes, pred assertions are available. // If the pred is (a non-degenerate) BBJ_COND, fetch the appropriate out set. // - ASSERT_TP assertionsOut = pred->bbAssertionOut; + ASSERT_TP assertionsOut = pred->bbAssertionOut; + const bool useCondAssertions = pred->KindIs(BBJ_COND) && (pred->NumSucc() == 2); - if (pred->KindIs(BBJ_COND) && (pred->NumSucc() == 2)) + if (useCondAssertions) { if (block == pred->GetJumpDest()) { @@ -13919,7 +13921,7 @@ void Compiler::fgMorphBlock(BasicBlock* block, unsigned highestReachablePostorde // if (!hasPredAssertions) { - if (block->NumSucc() == 1) + if (pred->NumSucc() == 1) { apLocal = assertionsOut; } From f942edab5a891714b02f508a64b9c5faf1b9fcfa Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Fri, 17 Nov 2023 11:15:34 -0800 Subject: [PATCH 4/5] avoid jtrue assertions involving floating types --- src/coreclr/jit/assertionprop.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 92ee287ea1f05..fc3908b1d43f4 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -2205,6 +2205,13 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree) GenTree* op1 = relop->AsOp()->gtOp1->gtCommaStoreVal(); GenTree* op2 = relop->AsOp()->gtOp2->gtCommaStoreVal(); + // Avoid creating local assertions for float types. + // + if (optLocalAssertionProp && varTypeIsFloating(op1)) + { + return NO_ASSERTION_INDEX; + } + // Check for op1 or op2 to be lcl var and if so, keep it in op1. if ((op1->gtOper != GT_LCL_VAR) && (op2->gtOper == GT_LCL_VAR)) { From 3882492e2f2b70eb606e62397c24bd2c962c812d Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Mon, 27 Nov 2023 19:42:41 -0800 Subject: [PATCH 5/5] fix osr stress issue --- src/coreclr/jit/fgopt.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/coreclr/jit/fgopt.cpp b/src/coreclr/jit/fgopt.cpp index b5757ce3f291f..493fdb6c2c2ee 100644 --- a/src/coreclr/jit/fgopt.cpp +++ b/src/coreclr/jit/fgopt.cpp @@ -2888,6 +2888,13 @@ bool Compiler::fgOptimizeEmptyBlock(BasicBlock* block) } } + // Don't remove the fgEntryBB + // + if (opts.IsOSR() && (block == fgEntryBB)) + { + break; + } + #if defined(FEATURE_EH_FUNCLETS) /* Don't remove an empty block that is in a different EH region * from its successor block, if the block is the target of a