public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Noah Goldstein <goldstein.w.n@gmail.com>
Cc: "H.J. Lu" <hjl.tools@gmail.com>,
	gcc-patches List <gcc-patches@gcc.gnu.org>,
	"Carlos O'Donell" <carlos@systemhalted.org>
Subject: Re: [PATCH v1] tree-optimization/95821 - Convert strlen + strchr to memchr
Date: Mon, 20 Jun 2022 21:04:15 +0200	[thread overview]
Message-ID: <YrDEr1msTTnnmWWc@tucnak> (raw)
In-Reply-To: <CAFUsyfLt1h2XxgBOPx1ROodNDeSx_YFTtdvGE=MgdPZDYsiOeQ@mail.gmail.com>

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, c, t);
> What do you mean by differentiate more? More comments? Or
> seperate the logic more?

Different code, don't add the 1 to the strlen value whenever you know
that chr can't be possibly 0 (either it is a non-zero constant,
or the compiler can prove it won't be zero at runtime otherwise).
Because if c is not 0, then memchr (x, c, strlen (x)) == memchr (x, c, strlen (x) + 1),
either c is among the first strlen (x) chars, or it will return NULL
because x[strlen (x)] == 0.

It actually is slightly more complicated, strchr second argument is int,
but we just care about the low 8 bits.
For TREE_CODE (chr) == INTEGER_CST, it is still trivial,
say integer_nonzerop (fold_convert (char_type_node, chr))
or equivalent using wide-int.h APIs.
For SSA_NAMEs, we'd need get_zero_bits API, but we only have
get_nonzero_bits, but we could say at least handle the case where
get_ssa_name_range_info gives a VR_RANGE or set of them where none of
the ranges include integral multiplies of 256.
But for start perhaps just handling INTEGER_CST chr would be good enough.

	Jakub


  reply	other threads:[~2022-06-20 19:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 16:35 Noah Goldstein
2022-06-20 17:29 ` Jakub Jelinek
2022-06-20 17:54   ` H.J. Lu
2022-06-20 18:48   ` Noah Goldstein
2022-06-20 19:04     ` Jakub Jelinek [this message]
2022-06-20 19:12       ` Noah Goldstein
2022-06-20 19:57         ` Jakub Jelinek
2022-06-20 20:59   ` Noah Goldstein
2022-06-20 21:42 ` [PATCH v2] " Noah Goldstein
2022-06-21 12:01   ` Jakub Jelinek
2022-06-21 18:13     ` Noah Goldstein
2022-07-07 16:26       ` Noah Goldstein
2022-06-21 18:12 ` [PATCH v3] " Noah Goldstein
2022-07-09 15:59   ` Jeff Law
2022-09-21 22:02     ` Noah Goldstein
2022-09-22 12:22   ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YrDEr1msTTnnmWWc@tucnak \
    --to=jakub@redhat.com \
    --cc=carlos@systemhalted.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=goldstein.w.n@gmail.com \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).