re PR tree-optimization/15738 ([tree-ssa] Convert strrchr(s, c) to strchr(s, c) if...
authorKazu Hirata <kazu@cs.umass.edu>
Wed, 2 Jun 2004 18:41:40 +0000 (18:41 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Wed, 2 Jun 2004 18:41:40 +0000 (18:41 +0000)
PR tree-optimization/15738.
* builtins.c (fold_builtin_strchr): Transform
strrchr (s, '\0') to strchr (s, '\0').

From-SVN: r82572

gcc/ChangeLog
gcc/builtins.c

index bb675bb3fea21e8ead9810cff4e917c65121552f..8d22422d99361343b564060715c7133fee9b380f 100644 (file)
@@ -1,3 +1,9 @@
+2004-06-02  Kazu Hirata  <kazu@cs.umass.edu>
+
+       PR tree-optimization/15738.
+       * builtins.c (fold_builtin_strchr): Transform
+       strrchr (s, '\0') to strchr (s, '\0').
+
 2004-06-02  Steven Bosscher  <stevenb@suse.de>
 
        * i386.c (ix86_adjust_cost): Don't increase the cost for
index e44ad61b7b2204fa0d46f43e83bca9c7ca530c5f..e2651866d6360e713d5eea214a2f8a2828811e32 100644 (file)
@@ -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;
     }
 }