Consider: extern char *strchr (__const char *__s, int __c) __attribute__ ((__pure__)); int foo (void) { int c = '1'; return (strchr ("<12ers", c) == 0); } Here is the last tree form. foo () { <bb 0>: return strchr ("<12ers", 49) == 0B; } This strchr seems to be optimized at expand time. As you might guess from the above testcase, GCC has a lot of redundant IS_EXPR_CODE_CLASS(CLASS), where CLASS is a compile-time constant. Optimizing these strchr away in turn allows us to remove a lot of dead code. It seems to be a simple extension to call simplify_builtin_strchr() from tree-ssa-ccp.c.
Confirmed.
Another possible place for this optimization would be fold_builtin().
This should be folded in ccp. Mind if I make this my weekend project?
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01275.html>.
The patch was approved with the modification suggested by RTH.
Subject: Bug 14819 CVSROOT: /cvs/gcc Module name: gcc Changes by: kazu@gcc.gnu.org 2004-05-30 21:05:21 Modified files: gcc : ChangeLog builtins.c Log message: PR tree-optimization/14819 * builtins.c (fold_builtin_strchr): New. (fold_builtin_1): Handle BUILT_IN_STRCHR and BUILT_IN_STRRCHR with fold_builtin_strchr(). Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3792&r2=2.3793 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/builtins.c.diff?cvsroot=gcc&r1=1.327&r2=1.328
Just checked in a patch: http://gcc.gnu.org/ml/gcc-cvs/2004-05/msg01066.html