Skip to content

Commit

Permalink
Fold constant compares and better loop detection
Browse files Browse the repository at this point in the history
  • Loading branch information
a74nh committed Jun 21, 2022
1 parent 34989bb commit 84f2ef4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12949,6 +12949,12 @@ GenTree* Compiler::gtFoldExprConditional(GenTree* tree)
DISPTREE(replacement);
JITDUMP("\n");

// If we bashed to a compare, try to fold that.
if (replacement->OperIsCompare())
{
return gtFoldExprCompare(replacement);
}

return replacement;
}

Expand Down
13 changes: 4 additions & 9 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4499,17 +4499,12 @@ bool Compiler::optIfConvert(BasicBlock* block)
// Arm only for now.
#ifdef TARGET_ARM64

// Don't optimise the block if it is inside a loop.
// Don't optimise the block if it is inside a loop
// When inside a loop, branches are quicker than selects.
if (fgHasLoops)
// Detect via the block weight as that will be high when inside a loop.
if (block->getBBWeight(this) > BB_UNITY_WEIGHT)
{
for (unsigned loopNum = 0; loopNum < optLoopCount; loopNum++)
{
if (optLoopTable[loopNum].lpContains(block))
{
return false;
}
}
return false;
}

// Does the block end by branching via a JTRUE after a compare?
Expand Down

0 comments on commit 84f2ef4

Please sign in to comment.