Skip to content

Commit

Permalink
Fix optSwitchConvert (#92249)
Browse files Browse the repository at this point in the history
Co-authored-by: Egor <egorbo@Egors-MacBook-Pro.local>
  • Loading branch information
EgorBo and Egor committed Sep 19, 2023
1 parent 41a8e39 commit b049f42
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/coreclr/jit/switchrecognition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,11 @@ bool Compiler::optSwitchConvert(BasicBlock* firstBlock, int testsCount, ssize_t*
maxValue = newMaxValue;
}

assert(testIdx <= testsCount);
if (testIdx < SWITCH_MIN_TESTS)
// testIdx is now representing the index of last good test value,
// Update testsCount as it's now potentially smaller than initially.
testsCount = testIdx;

if (testsCount < SWITCH_MIN_TESTS)
{
// Make sure we still have at least SWITCH_MIN_TESTS values after we filtered out some of them
return false;
Expand All @@ -304,7 +307,7 @@ bool Compiler::optSwitchConvert(BasicBlock* firstBlock, int testsCount, ssize_t*

// Find the last block in the chain
const BasicBlock* lastBlock = firstBlock;
for (int i = 0; i < testIdx - 1; i++)
for (int i = 0; i < testsCount - 1; i++)
{
lastBlock = lastBlock->bbNext;
}
Expand Down

0 comments on commit b049f42

Please sign in to comment.