Skip to content

Commit f72179a

Browse files
JIT: Remove fallthrough checks in Compiler::TryLowerSwitchToBitTest (#108106)
1 parent 5e9a425 commit f72179a

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

src/coreclr/jit/lower.cpp

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
13151315
// true if the switch has been lowered to a bit test
13161316
//
13171317
// Notes:
1318-
// If the jump table contains less than 32 (64 on 64 bit targets) entries and there
1318+
// If the jump table contains less than 32 (64 on 64-bit targets) entries and there
13191319
// are at most 2 distinct jump targets then the jump table can be converted to a word
13201320
// of bits where a 0 bit corresponds to one jump target and a 1 bit corresponds to the
13211321
// other jump target. Instead of the indirect jump a BT-JCC sequence is used to jump
@@ -1398,17 +1398,6 @@ bool Lowering::TryLowerSwitchToBitTest(FlowEdge* jumpTable[],
13981398
BasicBlock* bbCase0 = case0Edge->getDestinationBlock();
13991399
BasicBlock* bbCase1 = case1Edge->getDestinationBlock();
14001400

1401-
//
1402-
// One of the case blocks has to follow the switch block. This requirement could be avoided
1403-
// by adding a BBJ_ALWAYS block after the switch block but doing that sometimes negatively
1404-
// impacts register allocation.
1405-
//
1406-
1407-
if (!bbSwitch->NextIs(bbCase0) && !bbSwitch->NextIs(bbCase1))
1408-
{
1409-
return false;
1410-
}
1411-
14121401
JITDUMP("Lowering switch " FMT_BB " to bit test\n", bbSwitch->bbNum);
14131402

14141403
#if defined(TARGET_64BIT) && defined(TARGET_XARCH)
@@ -1428,10 +1417,9 @@ bool Lowering::TryLowerSwitchToBitTest(FlowEdge* jumpTable[],
14281417
#endif
14291418

14301419
//
1431-
// Rewire the blocks as needed and figure out the condition to use for JCC.
1420+
// Rewire the blocks as needed.
14321421
//
14331422

1434-
GenCondition bbSwitchCondition;
14351423
comp->fgRemoveAllRefPreds(bbCase1, bbSwitch);
14361424
comp->fgRemoveAllRefPreds(bbCase0, bbSwitch);
14371425

@@ -1457,20 +1445,7 @@ bool Lowering::TryLowerSwitchToBitTest(FlowEdge* jumpTable[],
14571445
case1Edge->setLikelihood(0.5);
14581446
}
14591447

1460-
if (bbSwitch->NextIs(bbCase0))
1461-
{
1462-
// GenCondition::C generates JC so we jump to bbCase1 when the bit is set
1463-
bbSwitchCondition = GenCondition::C;
1464-
bbSwitch->SetCond(case1Edge, case0Edge);
1465-
}
1466-
else
1467-
{
1468-
assert(bbSwitch->NextIs(bbCase1));
1469-
1470-
// GenCondition::NC generates JNC so we jump to bbCase0 when the bit is not set
1471-
bbSwitchCondition = GenCondition::NC;
1472-
bbSwitch->SetCond(case0Edge, case1Edge);
1473-
}
1448+
bbSwitch->SetCond(case1Edge, case0Edge);
14741449

14751450
var_types bitTableType = (bitCount <= (genTypeSize(TYP_INT) * 8)) ? TYP_INT : TYP_LONG;
14761451
GenTree* bitTableIcon = comp->gtNewIconNode(bitTable, bitTableType);
@@ -1481,13 +1456,13 @@ bool Lowering::TryLowerSwitchToBitTest(FlowEdge* jumpTable[],
14811456
//
14821457
GenTree* bitTest = comp->gtNewOperNode(GT_BT, TYP_VOID, bitTableIcon, switchValue);
14831458
bitTest->gtFlags |= GTF_SET_FLAGS;
1484-
GenTreeCC* jcc = comp->gtNewCC(GT_JCC, TYP_VOID, bbSwitchCondition);
1459+
GenTreeCC* jcc = comp->gtNewCC(GT_JCC, TYP_VOID, GenCondition::C);
14851460
LIR::AsRange(bbSwitch).InsertAfter(switchValue, bitTableIcon, bitTest, jcc);
14861461
#else // TARGET_XARCH
14871462
//
14881463
// Fallback to AND(RSZ(bitTable, switchValue), 1)
14891464
//
1490-
GenTree* tstCns = comp->gtNewIconNode(bbSwitch->NextIs(bbCase0) ? 1 : 0, bitTableType);
1465+
GenTree* tstCns = comp->gtNewIconNode(1, bitTableType);
14911466
GenTree* shift = comp->gtNewOperNode(GT_RSZ, bitTableType, bitTableIcon, switchValue);
14921467
GenTree* one = comp->gtNewIconNode(1, bitTableType);
14931468
GenTree* andOp = comp->gtNewOperNode(GT_AND, bitTableType, shift, one);

0 commit comments

Comments
 (0)