fold strchr (e, 0) to e + strlen (e)

Prathamesh Kulkarni bilbotheelffriend@gmail.com
Sat Feb 15 08:53:00 GMT 2014


This patch folds strchr (e, 0) to e + strlen (e), if e has no side-effects.
Bootstrapped, regtested on x86_64-unknown-linux-gnu
Ok for trunk ?

[gcc]
* gcc/builtins.c (fold_builtin_strchr):  returns tree for s1 + strlen (s1)
if TREE_SIDE_EFFECTS (s1) is false and integer_zerop (s2) is true.

[gcc/testsuite]
* gcc.dg/strlenopt-5.c: modified dg-final
scan-tree-dump-times for strchr and strlen
* gcc.dg/strlenopt-7.c: Likewise
* gcc.dg/strlenopt-9.c: Likewise
* gcc.dg/strlenopt-20.c: Likewise
* gcc.dg/strlenopt-21.c: Likewise
* gcc.dg/strlenopt-22.c: Likewise
* gcc.dg/strlenopt-22g.c: Likewise
* gcc.dg/strlenopt-26.c: Likewise
* gcc.c-torture/execute/builtins/strchr.c: added test case

Thanks and Regards,
Prathamesh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simplify-strchr.patch
Type: text/x-patch
Size: 11298 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140215/40f01a9e/attachment.bin>


More information about the Gcc-patches mailing list