This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: fold strchr (e, 0) to e + strlen (e)
- From: Prathamesh Kulkarni <bilbotheelffriend at gmail dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 15 Feb 2014 15:15:54 +0530
- Subject: Re: fold strchr (e, 0) to e + strlen (e)
- Authentication-results: sourceware.org; auth=none
- References: <CAJXstsDW938xmtRqxEoEkbwMiuFSVOsHPkzAF-+PEqLA5+gm7A at mail dot gmail dot com> <20140215085840 dot GK20378 at tucnak dot redhat dot com>
On Sat, Feb 15, 2014 at 2:28 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Sat, Feb 15, 2014 at 02:23:24PM +0530, Prathamesh Kulkarni wrote:
>> 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 ?
>
> Why do you think it is a good idea? It is often very much the opposite.
I maybe completely wrong, but since strchr(p, 0), matches each
character of p with c until '\0' is found, I thought it would be
faster to call strlen, since strlen would just skip over characters upto '\0'.
Also, I saw this committed in llvm trunk recently, and thought it
might be a good idea:
http://llvm-reviews.chandlerc.com/rL200736
>
> Jakub