From: Kazu Hirata Date: Wed, 2 Jun 2004 18:41:40 +0000 (+0000) Subject: re PR tree-optimization/15738 ([tree-ssa] Convert strrchr(s, c) to strchr(s, c) if... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=91fa0e3de67af533eeeb8ef494a2bb66187570c1;p=gcc.git re PR tree-optimization/15738 ([tree-ssa] Convert strrchr(s, c) to strchr(s, c) if c is known to be 0) PR tree-optimization/15738. * builtins.c (fold_builtin_strchr): Transform strrchr (s, '\0') to strchr (s, '\0'). From-SVN: r82572 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bb675bb3fea..8d22422d993 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-06-02 Kazu Hirata + + PR tree-optimization/15738. + * builtins.c (fold_builtin_strchr): Transform + strrchr (s, '\0') to strchr (s, '\0'). + 2004-06-02 Steven Bosscher * i386.c (ix86_adjust_cost): Don't increase the cost for diff --git a/gcc/builtins.c b/gcc/builtins.c index e44ad61b7b2..e2651866d63 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -7123,6 +7123,21 @@ fold_builtin_strchr (tree exp, bool actually_strrchr) ssize_int (r - p1)))); } + if (actually_strrchr) + { + tree fn; + + if (!integer_zerop (s2)) + return 0; + + fn = implicit_built_in_decls[BUILT_IN_STRCHR]; + if (!fn) + return 0; + + /* Transform strrchr(s1, '\0') to strchr(s1, '\0'). */ + return build_function_call_expr (fn, arglist); + } + return 0; } }