9
9
// We mainly rely on TryLowerSwitchToBitTest in these heuristics, but jump tables can be useful
10
10
// even without conversion to a bitmap test.
11
11
#define SWITCH_MAX_DISTANCE ((TARGET_POINTER_SIZE * BITS_IN_BYTE) - 1 )
12
- #define SWITCH_MIN_TESTS 4
12
+ #define SWITCH_MIN_TESTS 3
13
13
14
14
// -----------------------------------------------------------------------------
15
- // optSwitchRecognition: Optimize range check for if (A || B || C || D) pattern and convert it to Switch block
15
+ // optSwitchRecognition: Optimize range check for `x == cns1 || x == cns2 || x == cns3 ...`
16
+ // pattern and convert it to Switch block (jump table) which is then *might* be converted
17
+ // to a bitmap test via TryLowerSwitchToBitTest.
18
+ // TODO: recognize general jump table patterns.
16
19
//
17
- // Returns:
18
- // MODIFIED_NOTHING if no optimization is performed.
19
- // MODIFIED_EVERYTHING otherwise.
20
- //
21
- // Notes:
22
- // Detect if (a == val1 || a == val2 || a == val3 || ...) pattern and change it to switch tree
23
- // to reduce compares and jumps, and perform bit operation instead in Lowering phase.
24
- // This optimization is performed only for integer types.
20
+ // Return Value:
21
+ // MODIFIED_EVERYTHING if the optimization was applied.
25
22
//
26
23
PhaseStatus Compiler::optSwitchRecognition ()
27
24
{
25
+ // Limit to XARCH, ARM is already doing a great job with such comparisons using
26
+ // a series of ccmp instruction (see ifConvert phase).
27
+ #ifdef TARGET_XARCH
28
28
bool modified = false ;
29
29
for (BasicBlock* block = fgFirstBB; block != nullptr ; block = block->bbNext )
30
30
{
@@ -41,7 +41,7 @@ PhaseStatus Compiler::optSwitchRecognition()
41
41
fgUpdateChangedFlowGraph (FlowGraphUpdates::COMPUTE_BASICS);
42
42
return PhaseStatus::MODIFIED_EVERYTHING;
43
43
}
44
-
44
+ # endif
45
45
return PhaseStatus::MODIFIED_NOTHING;
46
46
}
47
47
0 commit comments