]> gcc.gnu.org Git - gcc.git/commit
Simplify memchr with small constant strings
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 17 Jun 2022 14:33:06 +0000 (07:33 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 14 Jul 2022 21:10:17 +0000 (14:10 -0700)
commitc6cf555a88f8ffb8ec85c2b94fe656ab217260ea
treefac88fef4d594a13125d3f361569adae0c57446a
parent748f8a8b145dde59c7b63aa68b5a59515b7efc49
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.
13 files changed:
gcc/testsuite/c-c++-common/pr103798-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-10.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-5.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-6.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-7.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-8.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr103798-9.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.cc
gcc/tree-ssa-strlen.cc
gcc/tree-ssa-strlen.h
This page took 0.065986 seconds and 6 git commands to generate.