From 91fa0e3de67af533eeeb8ef494a2bb66187570c1 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 2 Jun 2004 18:41:40 +0000 Subject: [PATCH] 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 --- gcc/ChangeLog | 6 ++++++ gcc/builtins.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bb675bb..8d22422 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 e44ad61..e265186 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; } } -- 2.7.4