Re: [PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr

2022-06-20 Thread Noah Goldstein via Gcc-patches
On Mon, Jun 20, 2022 at 10:29 AM Jakub Jelinek wrote: > > On Mon, Jun 20, 2022 at 09:35:36AM -0700, Noah Goldstein via Gcc-patches > wrote: > > This patch allows for strchr(x, c) to the replace with memchr(x, c, > > strlen(x) + 1) if strlen(x) has already been computed earlier in the > > tree. >

Re: [PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr

2022-06-20 Thread Jakub Jelinek via Gcc-patches
On Mon, Jun 20, 2022 at 12:12:53PM -0700, Noah Goldstein wrote: > Got it. Will have that in V2. Thanks. > > We could also make the initial: > bool is_strchr_zerop = integer_zerop (chr); > > Only check the lower 8 bits. Sure. Though, in that case it is just an optimization, it is ok to not to

Re: [PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr

2022-06-20 Thread Noah Goldstein via Gcc-patches
On Mon, Jun 20, 2022 at 12:04 PM Jakub Jelinek wrote: > > On Mon, Jun 20, 2022 at 11:48:24AM -0700, Noah Goldstein wrote: > > > I think we should differentiate more. If integer_nonzerop (chr) > > > or perhaps better tree_expr_nonzero_p (chr), then it is better > > > to optimize t = strlen (x);

Re: [PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr

2022-06-20 Thread Jakub Jelinek via Gcc-patches
On Mon, Jun 20, 2022 at 11:48:24AM -0700, Noah Goldstein wrote: > > I think we should differentiate more. If integer_nonzerop (chr) > > or perhaps better tree_expr_nonzero_p (chr), then it is better > > to optimize t = strlen (x); ... p = strchr (x, c); to > > t = strlen (x); ... p = memchr (x,

Re: [PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr

2022-06-20 Thread Noah Goldstein via Gcc-patches
On Mon, Jun 20, 2022 at 10:29 AM Jakub Jelinek wrote: > > On Mon, Jun 20, 2022 at 09:35:36AM -0700, Noah Goldstein via Gcc-patches > wrote: > > This patch allows for strchr(x, c) to the replace with memchr(x, c, > > strlen(x) + 1) if strlen(x) has already been computed earlier in the > > tree. >

Re: [PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr

2022-06-20 Thread H.J. Lu via Gcc-patches
On Mon, Jun 20, 2022 at 10:29 AM Jakub Jelinek wrote: > > On Mon, Jun 20, 2022 at 09:35:36AM -0700, Noah Goldstein via Gcc-patches > wrote: > > This patch allows for strchr(x, c) to the replace with memchr(x, c, > > strlen(x) + 1) if strlen(x) has already been computed earlier in the > > tree. >

Re: [PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr

2022-06-20 Thread Jakub Jelinek via Gcc-patches
On Mon, Jun 20, 2022 at 09:35:36AM -0700, Noah Goldstein via Gcc-patches wrote: > This patch allows for strchr(x, c) to the replace with memchr(x, c, > strlen(x) + 1) if strlen(x) has already been computed earlier in the > tree. > > Handles PR95821:

[PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr

2022-06-20 Thread Noah Goldstein via Gcc-patches
This patch allows for strchr(x, c) to the replace with memchr(x, c, strlen(x) + 1) if strlen(x) has already been computed earlier in the tree. Handles PR95821: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95821 Since memchr doesn't need to re-find the null terminator it is faster than strchr.