Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,11 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
afterDefaultCondBlock->inheritWeight(originalSwitchBB);
afterDefaultCondBlock->scaleBBWeight(switchLikelihood);

bool useJumpSequence = jumpCnt < minSwitchTabJumpCnt;
// Prefer direct branches for small switches. Leave two in-range targets eligible for a bit test.
constexpr unsigned maxJumpSequenceCases = TargetArchitecture::IsArm64 ? 7 : 3;
const unsigned inRangeTargetCount = targetCnt - ((defaultEdge->getDupCount() == 0) ? 1 : 0);
bool useJumpSequence =
(jumpCnt < minSwitchTabJumpCnt) || ((jumpCnt - 1 <= maxJumpSequenceCases) && (inRangeTargetCount > 2));

if (TargetOS::IsUnix && TargetArchitecture::IsArm32)
{
Expand All @@ -1038,7 +1042,7 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
// If we originally had 2 unique successors, check to see whether there is a unique
// non-default case, in which case we can eliminate the switch altogether.
// Note that the single unique successor case is handled above.
if ((targetCnt == 2) && (defaultEdge->getDupCount() == 0))
if (inRangeTargetCount == 1)
{
// The default case was peeled off, and we have only one other unique successor.
// Jump directly to this remaining successor.
Expand Down
Loading