From 5f404f622e3aaa5bfb1adb810f66bb2446636aae Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Tue, 28 Nov 2023 11:14:04 -0500 Subject: [PATCH 1/3] Enable peephole opt for non-debug code --- src/coreclr/jit/block.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/block.cpp b/src/coreclr/jit/block.cpp index db4f43d206c915..55de5f255e3a05 100644 --- a/src/coreclr/jit/block.cpp +++ b/src/coreclr/jit/block.cpp @@ -298,9 +298,9 @@ bool BasicBlock::IsFirstColdBlock(Compiler* compiler) const bool BasicBlock::CanRemoveJumpToNext(Compiler* compiler) { assert(KindIs(BBJ_ALWAYS)); - const bool tryJumpOpt = compiler->opts.OptimizationEnabled() || ((bbFlags & BBF_NONE_QUIRK) != 0); - const bool skipJump = tryJumpOpt && JumpsToNext() && !hasAlign() && ((bbFlags & BBF_KEEP_BBJ_ALWAYS) == 0) && - !compiler->fgInDifferentRegions(this, bbJumpDest); + const bool tryJumpOpt = !compiler->opts.compDbgCode || ((bbFlags & BBF_NONE_QUIRK) != 0); + const bool skipJump = + tryJumpOpt && JumpsToNext() && !hasAlign() && !compiler->fgInDifferentRegions(this, bbJumpDest); return skipJump; } From 3321e5fdee4c18ed93e5215e8bc966719e90cbcc Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 29 Nov 2023 20:35:17 -0500 Subject: [PATCH 2/3] Enable peephole opt for all MinOpts scenarios --- src/coreclr/jit/block.cpp | 8 ++------ src/coreclr/jit/codegenlinear.cpp | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/coreclr/jit/block.cpp b/src/coreclr/jit/block.cpp index 55de5f255e3a05..bc2f578cf1c98b 100644 --- a/src/coreclr/jit/block.cpp +++ b/src/coreclr/jit/block.cpp @@ -292,16 +292,12 @@ bool BasicBlock::IsFirstColdBlock(Compiler* compiler) const // compiler - current compiler instance // // Returns: -// true if the peephole optimization is enabled, -// and block is a BBJ_ALWAYS to the next block that we can fall through into +// true if block is a BBJ_ALWAYS to the next block that we can fall into // bool BasicBlock::CanRemoveJumpToNext(Compiler* compiler) { assert(KindIs(BBJ_ALWAYS)); - const bool tryJumpOpt = !compiler->opts.compDbgCode || ((bbFlags & BBF_NONE_QUIRK) != 0); - const bool skipJump = - tryJumpOpt && JumpsToNext() && !hasAlign() && !compiler->fgInDifferentRegions(this, bbJumpDest); - return skipJump; + return (JumpsToNext() && !hasAlign() && !compiler->fgInDifferentRegions(this, bbJumpDest)); } //------------------------------------------------------------------------ diff --git a/src/coreclr/jit/codegenlinear.cpp b/src/coreclr/jit/codegenlinear.cpp index 56e62fcbba34ed..ab62d35e6e85c6 100644 --- a/src/coreclr/jit/codegenlinear.cpp +++ b/src/coreclr/jit/codegenlinear.cpp @@ -731,9 +731,7 @@ void CodeGen::genCodeForBBlist() case BBJ_ALWAYS: { - // Peephole optimization: If this block jumps to the next one, skip emitting the jump - // (unless we are jumping between hot/cold sections, or if we need the jump for EH reasons) - // (Skip this if optimizations are disabled, unless the block shouldn't have a jump in the first place) + // If this block jumps to the next one, we might be able to skip emitting the jump if (block->CanRemoveJumpToNext(compiler)) { #ifdef TARGET_AMD64 From c64c8516f5f18e354894cdb326b6c975af4e046f Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 29 Nov 2023 20:55:18 -0500 Subject: [PATCH 3/3] Style --- src/coreclr/jit/block.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/block.cpp b/src/coreclr/jit/block.cpp index bc2f578cf1c98b..f7d6127c585c39 100644 --- a/src/coreclr/jit/block.cpp +++ b/src/coreclr/jit/block.cpp @@ -297,7 +297,7 @@ bool BasicBlock::IsFirstColdBlock(Compiler* compiler) const bool BasicBlock::CanRemoveJumpToNext(Compiler* compiler) { assert(KindIs(BBJ_ALWAYS)); - return (JumpsToNext() && !hasAlign() && !compiler->fgInDifferentRegions(this, bbJumpDest)); + return JumpsToNext() && !hasAlign() && !compiler->fgInDifferentRegions(this, bbJumpDest); } //------------------------------------------------------------------------