This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] builtins.c: Fix PR tree-optimization/15738.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: roger at eyesopen dot com
- Date: Tue, 01 Jun 2004 01:07:05 -0400 (EDT)
- Subject: [patch] builtins.c: Fix PR tree-optimization/15738.
Hi,
Attached is a patch to fix PR tree-optimization/15738.
Consider:
char *
foo (const char *s)
{
int c = 0;
return strrchr (s, c);
}
The last tree-ssa form looks like so:
foo (s)
{
int c;
char * T.0;
<bb 0>:
T.0_3 = strrchr (s_2, 0) [tail call];
return T.0_3;
}
Note that strrchr (s_2, 0) is not converted to strchr (s_2, 0).
The patch fixes the problem by copying the last few lines of
simplify_builtin_strrchr() to fold_builtin_strchr().
Once this PR is fixed, we should be able to remove
expand_builtin_strchr() and expand_builtin_strrchr().
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2004-05-31 Kazu Hirata <kazu@cs.umass.edu>
PR tree-optimization/15738.
* builtins.c (fold_builtin_strchr): Transform
strrchr (s, '\0') to strchr (s, '\0').
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.329
diff -u -r1.329 builtins.c
--- builtins.c 31 May 2004 09:13:33 -0000 1.329
+++ builtins.c 31 May 2004 17:43:18 -0000
@@ -7123,6 +7123,21 @@
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;
}
}