Skip to content

Commit b049f42

Browse files
EgorBoEgor
and
Egor
authored
Fix optSwitchConvert (dotnet#92249)
Co-authored-by: Egor <egorbo@Egors-MacBook-Pro.local>
1 parent 41a8e39 commit b049f42

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/coreclr/jit/switchrecognition.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,11 @@ bool Compiler::optSwitchConvert(BasicBlock* firstBlock, int testsCount, ssize_t*
289289
maxValue = newMaxValue;
290290
}
291291

292-
assert(testIdx <= testsCount);
293-
if (testIdx < SWITCH_MIN_TESTS)
292+
// testIdx is now representing the index of last good test value,
293+
// Update testsCount as it's now potentially smaller than initially.
294+
testsCount = testIdx;
295+
296+
if (testsCount < SWITCH_MIN_TESTS)
294297
{
295298
// Make sure we still have at least SWITCH_MIN_TESTS values after we filtered out some of them
296299
return false;
@@ -304,7 +307,7 @@ bool Compiler::optSwitchConvert(BasicBlock* firstBlock, int testsCount, ssize_t*
304307

305308
// Find the last block in the chain
306309
const BasicBlock* lastBlock = firstBlock;
307-
for (int i = 0; i < testIdx - 1; i++)
310+
for (int i = 0; i < testsCount - 1; i++)
308311
{
309312
lastBlock = lastBlock->bbNext;
310313
}

0 commit comments

Comments
 (0)