-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
It would be useful if the JIT recognized tests like:
if ('0' <= c && c <= '9')- can be reduced to a single branch + compare + subtractif (c == ' ' || c == '\t' || c == '\r' || c == '\n')- can be reduced to 2 branches + compare + bit test (BT instruction)
The second variant is sometimes implemented using a switch/jump table (in which case is much more simpler to recognize):
switch (c) {
case ' ':
case '\t':
case '\r':
case '\n':
return true;
default:
return false;
}The reduction in number of conditional branches to 1 or 2 can make other optimizations more effective - if-conversion in particular.
Similar issue in the Roslyn repository: https://github.com/dotnet/roslyn/issues/20375
The first variant can be implemented by managed compilers but getting good code for the second is problematic if the target arch bitness is not known. Also, the BT instruction is not available in IL so it has to be simulated with shift/and/compare which the JIT has to recognize.
category:cq
theme:basic-cq
skill-level:intermediate
cost:medium