llvm/lib
Benjamin Kramer fd48a80e14 [SimplifyLibCalls] Turn memchr(const, C, const) into a bitfield check.
strchr("123!", C) != nullptr is a common pattern to check if C is one
of 1, 2, 3 or !. If the largest element of the string is smaller than
the target's register size we can easily create a bitfield and just
do a simple test for set membership.

int foo(char C) { return strchr("123!", C) != nullptr; } now becomes

	cmpl	$64, %edi ## range check
	sbbb	%al, %al
	movabsq	$0xE000200000001, %rcx
	btq	%rdi, %rcx ## bit test
	sbbb	%cl, %cl
	andb	%al, %cl ## and the two conditions
	andb	$1, %cl
	movzbl	%cl, %eax ## returning an int
	ret

(imho the backend should expand this into a series of branches, but
that's a different story)

The code is currently limited to bit fields that fit in a register, so
usually 64 or 32 bits. Sadly, this misses anything using alpha chars
or {}. This could be fixed by just emitting a i128 bit field, but that
can generate really ugly code so we have to find a better way. To some
degree this is also recreating switch lowering logic, but we can't
simply emit a switch instruction and thus change the CFG within
instcombine.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232902 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-21 21:09:33 +00:00
..
Analysis ValueTracking: Forward getConstantStringInfo's TrimAtNul param into recursive invocation 2015-03-21 15:36:06 +00:00
AsmParser AsmParser: Stop requiring 'name:' when it's not printed 2015-03-16 19:01:54 +00:00
Bitcode Internalize BitcodeReader. Not used outside of BitcodeReader.cpp. 2015-03-17 20:40:24 +00:00
CodeGen Cache the Function dependent subtarget on the MachineFunction. 2015-03-21 03:13:10 +00:00
DebugInfo
ExecutionEngine Fix uses of reserved identifiers starting with an underscore followed by an uppercase letter 2015-03-16 18:06:57 +00:00
Fuzzer
IR Verifier: Check that !dbg attachments have the right type 2015-03-20 19:26:58 +00:00
IRReader
LineEditor
Linker DataLayout is mandatory, update the API to reflect it with references. 2015-03-10 02:37:25 +00:00
LTO Verifier: Remove the separate -verify-di pass 2015-03-19 22:24:17 +00:00
MC Don't declare all text sections at the start of the .s 2015-03-20 20:00:01 +00:00
Object Be lazy about loading metadata in IRObjectFile. 2015-03-13 21:54:20 +00:00
Option Make getLastArgNoClaim work for up to 4 arguments. 2015-03-20 23:32:58 +00:00
Passes [PM] Fixup for r231556 where I missed a dependency on intrinsics 2015-03-07 09:08:20 +00:00
ProfileData InstrProf: Fix CoverageMappingReader on big endian 2015-03-16 21:40:18 +00:00
Support Note that we don't support COFF on PPC. 2015-03-19 02:40:56 +00:00
TableGen
Target [SimplifyLibCalls] Turn memchr(const, C, const) into a bitfield check. 2015-03-21 21:09:33 +00:00
Transforms [SimplifyLibCalls] Turn memchr(const, C, const) into a bitfield check. 2015-03-21 21:09:33 +00:00
CMakeLists.txt [PM] Create a separate library for high-level pass management code. 2015-03-07 09:02:36 +00:00
LLVMBuild.txt [PM] Create a separate library for high-level pass management code. 2015-03-07 09:02:36 +00:00
Makefile [PM] Create a separate library for high-level pass management code. 2015-03-07 09:02:36 +00:00