This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Exploiting knowing sizes of string.
- From: Jakub Jelinek <jakub at redhat dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: Joseph Myers <joseph at codesourcery dot com>, Richard Earnshaw <Richard dot Earnshaw at foss dot arm dot com>, gcc at gcc dot gnu dot org
- Date: Thu, 4 Jun 2015 21:57:59 +0200
- Subject: Re: Exploiting knowing sizes of string.
- Authentication-results: sourceware.org; auth=none
- References: <20150604105929 dot GA19141 at domone> <alpine dot DEB dot 2 dot 10 dot 1506041206200 dot 31862 at digraph dot polyomino dot org dot uk> <20150604123319 dot GF10247 at tucnak dot redhat dot com> <20150604125331 dot GA22076 at domone> <20150604125920 dot GG10247 at tucnak dot redhat dot com> <20150604142304 dot GA23875 at domone> <5570757D dot 8050809 at foss dot arm dot com> <alpine dot DEB dot 2 dot 10 dot 1506041559020 dot 12011 at digraph dot polyomino dot org dot uk> <20150604163632 dot GA26222 at domone>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Jun 04, 2015 at 06:36:33PM +0200, OndÅej BÃlka wrote:
> On Thu, Jun 04, 2015 at 04:01:50PM +0000, Joseph Myers wrote:
> > On Thu, 4 Jun 2015, Richard Earnshaw wrote:
> >
> > > > Change that into
> > > >
> > > > int foo(char *s)
> > > > {
> > > > int l = strlen (s);
> > > > char *p = memchr (s, 'a', l);
> > > > return p+l;
> > > > }
> And Joseph you shouldn't restrict yourself only to values that are
> present in variables to cover case where its implicit one from strcpy
> converted to stpcpy.
memchr isn't handled in that pass right now at all, of course it could be
added, shouldn't be really hard. Feel free to file a PR and/or write
a patch.
As for e.g. the inlining of the first (or a few more) iterations of strcmp
etc., that is certainly something that can be done in the compiler too and
the compiler should have much better information whether to do it or not,
as it shouldn't be done for -Os, or for basic blocks or functions predicted
cold, because it enlarges the code size quite a lot.
For strcmp in particular, right now we handle the cast of two string
literals at compile time, or e.g. strcmp (str, ""). For anything further,
supposedly it should check if the target has inline expansion of strcmp
(e.g. s390 or sh have them), then inlining one iteration is hardly
beneficial.
Jakub