Skip to content
Snippets Groups Projects
Commit c6cf555a authored by H.J. Lu's avatar H.J. Lu
Browse files

Simplify memchr with small constant strings

When memchr is applied on a constant string of no more than the bytes of
a word, simplify memchr by checking each byte in the constant string.

int f (int a)
{
   return  __builtin_memchr ("AE", a, 2) != 0;
}

is simplified to

int f (int a)
{
  return ((char) a == 'A' || (char) a == 'E') != 0;
}

gcc/

	PR tree-optimization/103798
	* tree-ssa-forwprop.cc: Include "tree-ssa-strlen.h".
	(simplify_builtin_call): Inline memchr with constant strings of
	no more than the bytes of a word.
	* tree-ssa-strlen.cc (use_in_zero_equality): Make it global.
	* tree-ssa-strlen.h (use_in_zero_equality): New.

gcc/testsuite/

	PR tree-optimization/103798
	* c-c++-common/pr103798-1.c: New test.
	* c-c++-common/pr103798-2.c: Likewise.
	* c-c++-common/pr103798-3.c: Likewise.
	* c-c++-common/pr103798-4.c: Likewise.
	* c-c++-common/pr103798-5.c: Likewise.
	* c-c++-common/pr103798-6.c: Likewise.
	* c-c++-common/pr103798-7.c: Likewise.
	* c-c++-common/pr103798-8.c: Likewise.
	* c-c++-common/pr103798-9.c: Likewise.
	* c-c++-common/pr103798-10.c: Likewise.
parent 748f8a8b
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment