[PATCH] Optimize strchr("abc", 'c'), strrchr("abc", 'c'), strcmp("a","b") and strstr("abc","bc") (take 2)

Richard Henderson rth@redhat.com
Wed Nov 8 17:30:00 GMT 2000


On Wed, Nov 08, 2000 at 01:36:58PM +0100, Jakub Jelinek wrote:
> 	* builtins.c (c_strlen): Use TREE_STRING_LENGTH - 1 for max.
> 	(c_getstr): New function.
> 	(expand_builtin_strstr): Do nothing if -fcheck-memory-usage.
> 	If both arguments are constant string, optimize out.
> 	(expand_builtin_strchr, expand_builtin_strrchr): New functions.
> 	(expand_builtin_strpbrk): Use c_getstr, do nothing if
> 	-fcheck-memory-usage.
> 	(expand_builtin_fputs): Likewise.
> 	(expand_builtin_strcmp): Add MODE argument.
> 	Use even if !HAVE_cmpstrsi.
> 	Optimize the case when both arguments are constant strings.
> 	(expand_builtin): Adjust expand_builtin_strcmp caller.
> 	Call expand_builtin_strchr and expand_builtin_strrchr.
> 	* c-common.c (c_common_nodes_and_builtins): Add strchr and strrchr
> 	builtins.
> 	* builtins.def (BUILT_IN_STRRCHR): Add.
> 
> 	* gcc.c-torture/execute/string-opt-1.c: Add test for strstr
> 	with both arguments constant strings.
> 	* gcc.c-torture/execute/string-opt-3.c: New test.
> 	* gcc.c-torture/execute/string-opt-4.c: New test.
> 	* gcc.c-torture/execute/string-opt-5.c: New test.

Generally ok.

> +expand_builtin_strcmp (exp, target, mode)
>       tree exp;
>       rtx target;
> +     enum machine_mode mode;
>  {
>    tree arglist = TREE_OPERAND (exp, 1);
> +  tree arg1, arg2;
> +  char *p1, *p2;

Missing const.



r~


More information about the Gcc-patches mailing list