public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/61056] New: strchr (x, 0) is not converted to strlen (x)
@ 2014-05-04 16:22 olegendo at gcc dot gnu.org
  2014-05-04 16:47 ` [Bug tree-optimization/61056] " jakub at gcc dot gnu.org
  2014-05-04 16:59 ` olegendo at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: olegendo at gcc dot gnu.org @ 2014-05-04 16:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61056

            Bug ID: 61056
           Summary: strchr (x, 0) is not converted to strlen (x)
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olegendo at gcc dot gnu.org
            Target: sh*-*-*

At least on SH and r210026 the following:

extern "C" const char* strchr (const char*,int);

const char* test (const char* x)
{
  return strrchr (x, 0);
}

does not get converted to a strlen (x).  It seems that tree-ssa-strlen is
trying to do something but always fails.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/61056] strchr (x, 0) is not converted to strlen (x)
  2014-05-04 16:22 [Bug tree-optimization/61056] New: strchr (x, 0) is not converted to strlen (x) olegendo at gcc dot gnu.org
@ 2014-05-04 16:47 ` jakub at gcc dot gnu.org
  2014-05-04 16:59 ` olegendo at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-05-04 16:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61056

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
1) your testcase uses strrchr rather than strchr
2) why do you think it is desirable to convert strchr (x, 0) to x + strlen (x)?
Unless you have good library implementation for the latter and bad for the
former, strchr (x, 0) should be a win.
What the strlen pass does is that if you e.g. use strchr (x, 0) or strlen (x)
several times when the lengths of the strings actually can't change in between,
it can avoid the second and following call.  And, it is able to deal even with
strlen (x) used in one place and strchr (x, 0) in another or vice versa etc.
(plus various other optimizations).


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/61056] strchr (x, 0) is not converted to strlen (x)
  2014-05-04 16:22 [Bug tree-optimization/61056] New: strchr (x, 0) is not converted to strlen (x) olegendo at gcc dot gnu.org
  2014-05-04 16:47 ` [Bug tree-optimization/61056] " jakub at gcc dot gnu.org
@ 2014-05-04 16:59 ` olegendo at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: olegendo at gcc dot gnu.org @ 2014-05-04 16:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61056

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #1)
> 1) your testcase uses strrchr rather than strchr

Sorry, typo/pasto.  It was meant to be "strchr".

> 2) why do you think it is desirable to convert strchr (x, 0) to x + strlen
> (x)?

On SH we have a builtin strlen implementation.  I was just expecting strchr (x,
0) to utilize it, that's all.

> Unless you have good library implementation for the latter and bad for the
> former, strchr (x, 0) should be a win.
> What the strlen pass does is that if you e.g. use strchr (x, 0) or strlen
> (x) several times when the lengths of the strings actually can't change in
> between, it can avoid the second and following call.  And, it is able to
> deal even with strlen (x) used in one place and strchr (x, 0) in another or
> vice versa etc. (plus various other optimizations).

Ah, thanks for the explanation.
BTW, are there any plans to add true builtin strchr support so that it can be
expanded by the target code in the same way as strlen?


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-04 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-04 16:22 [Bug tree-optimization/61056] New: strchr (x, 0) is not converted to strlen (x) olegendo at gcc dot gnu.org
2014-05-04 16:47 ` [Bug tree-optimization/61056] " jakub at gcc dot gnu.org
2014-05-04 16:59 ` olegendo at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).