From b69d7355ebc31f906d5a3055e027b40361c4ee4f Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 12 Mar 2023 00:31:35 +0100 Subject: [PATCH 1/3] Fold RuntimeInformation.IsOSPlatform --- src/coreclr/jit/importervectorization.cpp | 3 +-- src/coreclr/jit/morph.cpp | 12 +++++++++--- .../src/System/OperatingSystem.cs | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/importervectorization.cpp b/src/coreclr/jit/importervectorization.cpp index bf1e67952cc2e..ff7d89923155d 100644 --- a/src/coreclr/jit/importervectorization.cpp +++ b/src/coreclr/jit/importervectorization.cpp @@ -731,10 +731,9 @@ GenTree* Compiler::impStringEqualsOrStartsWith(bool startsWith, CORINFO_SIG_INFO GenTreeLclVar* varStrLcl = gtNewLclvNode(varStrTmp, varStr->TypeGet()); // Create a tree representing string's Length: - // TODO-Unroll-CQ: Consider using ARR_LENGTH here, but we'll have to modify QMARK to propagate BBF_HAS_IDX_LEN int strLenOffset = OFFSETOF__CORINFO_String__stringLen; GenTree* lenOffset = gtNewIconNode(strLenOffset, TYP_I_IMPL); - GenTree* lenNode = gtNewIndir(TYP_INT, gtNewOperNode(GT_ADD, TYP_BYREF, varStrLcl, lenOffset)); + GenTree* lenNode = gtNewArrLen(TYP_INT, varStrLcl, strLenOffset, compCurBB); varStrLcl = gtClone(varStrLcl)->AsLclVar(); GenTree* unrolled = impExpandHalfConstEquals(varStrLcl, lenNode, needsNullcheck, startsWith, (WCHAR*)str, cnsLength, diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 971abb1c7dbb3..3f2ec6352bf7e 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -14544,8 +14544,10 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt) // if they are going to be cleared by fgSplitBlockAfterStatement(). We currently only do this only // for the GC safe point bit, the logic being that if 'block' was marked gcsafe, then surely // remainderBlock will still be GC safe. - BasicBlockFlags propagateFlags = block->bbFlags & BBF_GC_SAFE_POINT; - BasicBlock* remainderBlock = fgSplitBlockAfterStatement(block, stmt); + BasicBlockFlags propagateFlagsToRemainder = block->bbFlags & BBF_GC_SAFE_POINT; + // Conservatively mark all blocks as having IDX_LEN since we don't know where exactly it went + BasicBlockFlags propagateFlagsToAll = block->bbFlags & BBF_HAS_IDX_LEN; + BasicBlock* remainderBlock = fgSplitBlockAfterStatement(block, stmt); fgRemoveRefPred(remainderBlock, block); // We're going to put more blocks between block and remainderBlock. BasicBlock* condBlock = fgNewBBafter(BBJ_COND, block, true); @@ -14561,7 +14563,7 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt) elseBlock->bbFlags |= BBF_IMPORTED; } - remainderBlock->bbFlags |= propagateFlags; + remainderBlock->bbFlags |= (propagateFlagsToRemainder | propagateFlagsToAll); condBlock->inheritWeight(block); @@ -14569,6 +14571,9 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt) fgAddRefPred(elseBlock, condBlock); fgAddRefPred(remainderBlock, elseBlock); + condBlock->bbFlags |= propagateFlagsToAll; + elseBlock->bbFlags |= propagateFlagsToAll; + BasicBlock* thenBlock = nullptr; if (hasTrueExpr && hasFalseExpr) { @@ -14585,6 +14590,7 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt) thenBlock = fgNewBBafter(BBJ_ALWAYS, condBlock, true); thenBlock->bbJumpDest = remainderBlock; + thenBlock->bbFlags |= propagateFlagsToAll; if ((block->bbFlags & BBF_INTERNAL) == 0) { thenBlock->bbFlags &= ~BBF_INTERNAL; diff --git a/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs b/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs index 6fc2f2257fe7b..30d5455249d4c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs +++ b/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Versioning; @@ -115,6 +116,7 @@ public string VersionString /// Indicates whether the current application is running on the specified platform. /// /// Case-insensitive platform name. Examples: Browser, Linux, FreeBSD, Android, iOS, macOS, tvOS, watchOS, Windows. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) { ArgumentNullException.ThrowIfNull(platform); From 568f3d6868fad0be7c63ee7aa69105a5bbe4f4b3 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Sun, 12 Mar 2023 03:17:17 +0100 Subject: [PATCH 2/3] Update importervectorization.cpp --- src/coreclr/jit/importervectorization.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/jit/importervectorization.cpp b/src/coreclr/jit/importervectorization.cpp index ff7d89923155d..375c12035875b 100644 --- a/src/coreclr/jit/importervectorization.cpp +++ b/src/coreclr/jit/importervectorization.cpp @@ -732,7 +732,6 @@ GenTree* Compiler::impStringEqualsOrStartsWith(bool startsWith, CORINFO_SIG_INFO // Create a tree representing string's Length: int strLenOffset = OFFSETOF__CORINFO_String__stringLen; - GenTree* lenOffset = gtNewIconNode(strLenOffset, TYP_I_IMPL); GenTree* lenNode = gtNewArrLen(TYP_INT, varStrLcl, strLenOffset, compCurBB); varStrLcl = gtClone(varStrLcl)->AsLclVar(); From 642585ce4bc2d4a7843ca85559bdb263b3c1a79e Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Mon, 13 Mar 2023 14:34:18 +0100 Subject: [PATCH 3/3] Update morph.cpp --- src/coreclr/jit/morph.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 3f2ec6352bf7e..ba3e2749dfe5a 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -14545,8 +14545,8 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt) // for the GC safe point bit, the logic being that if 'block' was marked gcsafe, then surely // remainderBlock will still be GC safe. BasicBlockFlags propagateFlagsToRemainder = block->bbFlags & BBF_GC_SAFE_POINT; - // Conservatively mark all blocks as having IDX_LEN since we don't know where exactly it went - BasicBlockFlags propagateFlagsToAll = block->bbFlags & BBF_HAS_IDX_LEN; + // Conservatively propagate BBF_COPY_PROPAGATE flags to all blocks + BasicBlockFlags propagateFlagsToAll = block->bbFlags & BBF_COPY_PROPAGATE; BasicBlock* remainderBlock = fgSplitBlockAfterStatement(block, stmt); fgRemoveRefPred(remainderBlock, block); // We're going to put more blocks between block and remainderBlock.