Skip to content

Commit e07a59e

Browse files
authored
Constant folding for RuntimeInformation.IsOSPlatform(OSPlatform) (#83308)
1 parent a84fff9 commit e07a59e

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/coreclr/jit/importervectorization.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,8 @@ GenTree* Compiler::impStringEqualsOrStartsWith(bool startsWith, CORINFO_SIG_INFO
731731
GenTreeLclVar* varStrLcl = gtNewLclvNode(varStrTmp, varStr->TypeGet());
732732

733733
// Create a tree representing string's Length:
734-
// TODO-Unroll-CQ: Consider using ARR_LENGTH here, but we'll have to modify QMARK to propagate BBF_HAS_IDX_LEN
735734
int strLenOffset = OFFSETOF__CORINFO_String__stringLen;
736-
GenTree* lenOffset = gtNewIconNode(strLenOffset, TYP_I_IMPL);
737-
GenTree* lenNode = gtNewIndir(TYP_INT, gtNewOperNode(GT_ADD, TYP_BYREF, varStrLcl, lenOffset));
735+
GenTree* lenNode = gtNewArrLen(TYP_INT, varStrLcl, strLenOffset, compCurBB);
738736
varStrLcl = gtClone(varStrLcl)->AsLclVar();
739737

740738
GenTree* unrolled = impExpandHalfConstEquals(varStrLcl, lenNode, needsNullcheck, startsWith, (WCHAR*)str, cnsLength,

src/coreclr/jit/morph.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14544,8 +14544,10 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt)
1454414544
// if they are going to be cleared by fgSplitBlockAfterStatement(). We currently only do this only
1454514545
// for the GC safe point bit, the logic being that if 'block' was marked gcsafe, then surely
1454614546
// remainderBlock will still be GC safe.
14547-
BasicBlockFlags propagateFlags = block->bbFlags & BBF_GC_SAFE_POINT;
14548-
BasicBlock* remainderBlock = fgSplitBlockAfterStatement(block, stmt);
14547+
BasicBlockFlags propagateFlagsToRemainder = block->bbFlags & BBF_GC_SAFE_POINT;
14548+
// Conservatively propagate BBF_COPY_PROPAGATE flags to all blocks
14549+
BasicBlockFlags propagateFlagsToAll = block->bbFlags & BBF_COPY_PROPAGATE;
14550+
BasicBlock* remainderBlock = fgSplitBlockAfterStatement(block, stmt);
1454914551
fgRemoveRefPred(remainderBlock, block); // We're going to put more blocks between block and remainderBlock.
1455014552

1455114553
BasicBlock* condBlock = fgNewBBafter(BBJ_COND, block, true);
@@ -14561,14 +14563,17 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt)
1456114563
elseBlock->bbFlags |= BBF_IMPORTED;
1456214564
}
1456314565

14564-
remainderBlock->bbFlags |= propagateFlags;
14566+
remainderBlock->bbFlags |= (propagateFlagsToRemainder | propagateFlagsToAll);
1456514567

1456614568
condBlock->inheritWeight(block);
1456714569

1456814570
fgAddRefPred(condBlock, block);
1456914571
fgAddRefPred(elseBlock, condBlock);
1457014572
fgAddRefPred(remainderBlock, elseBlock);
1457114573

14574+
condBlock->bbFlags |= propagateFlagsToAll;
14575+
elseBlock->bbFlags |= propagateFlagsToAll;
14576+
1457214577
BasicBlock* thenBlock = nullptr;
1457314578
if (hasTrueExpr && hasFalseExpr)
1457414579
{
@@ -14585,6 +14590,7 @@ void Compiler::fgExpandQmarkStmt(BasicBlock* block, Statement* stmt)
1458514590

1458614591
thenBlock = fgNewBBafter(BBJ_ALWAYS, condBlock, true);
1458714592
thenBlock->bbJumpDest = remainderBlock;
14593+
thenBlock->bbFlags |= propagateFlagsToAll;
1458814594
if ((block->bbFlags & BBF_INTERNAL) == 0)
1458914595
{
1459014596
thenBlock->bbFlags &= ~BBF_INTERNAL;

src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Runtime.CompilerServices;
56
using System.Runtime.Serialization;
67
using System.Runtime.Versioning;
78

@@ -115,6 +116,7 @@ public string VersionString
115116
/// Indicates whether the current application is running on the specified platform.
116117
/// </summary>
117118
/// <param name="platform">Case-insensitive platform name. Examples: Browser, Linux, FreeBSD, Android, iOS, macOS, tvOS, watchOS, Windows.</param>
119+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
118120
public static bool IsOSPlatform(string platform)
119121
{
120122
ArgumentNullException.ThrowIfNull(platform);

0 commit comments

Comments
 (0)