public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "glisse at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/63464] compare one character to many: faster
Date: Tue, 07 Oct 2014 20:15:00 -0000	[thread overview]
Message-ID: <bug-63464-4-cMH7OOrctw@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-63464-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63464

--- Comment #6 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #1)
> We have this optimization implemented for switches,

Thanks, that's indeed the most natural place for it, although I hadn't thought
of testing that...

Glibc's strspn has:

__STRING_INLINE size_t
__strspn_c3 (const char *__s, int __accept1, int __accept2, int __accept3)
{
  size_t __result = 0;
  /* Please note that __accept1 to __accept3 never can be '\0'.  */
  while (__s[__result] == __accept1 || __s[__result] == __accept2
         || __s[__result] == __accept3)
    ++__result;
  return __result;
}


This is only called when optimizing and with a second argument that is a string
literal, but it is still inconvenient to turn that into a switch, so it seems
useful to optimize this form as well (well, maybe we could expand
__builtin_strspn in gcc instead so it also works for larger constant second
arguments, but creating a loop is not so nice and there are plenty of other
similar functions).

(By the way, those optimizations are protected by a test __builtin_constant_p
(s) which only seems to be true if passing _directly_ a string literal, maybe
__builtin_constant_p could be made to return true a bit more often, or glibc
could test instead __builtin_constant_p (s[0]) etc)

(For completeness, I also compared with a "repne scasb; je" version I found
somewhere in glibc, which was more than 20 times slower, and quite difficult to
generate since we don't allow clobbers on asm goto...)


  parent reply	other threads:[~2014-10-07 20:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-05 21:28 [Bug tree-optimization/63464] New: " glisse at gcc dot gnu.org
2014-10-06 11:27 ` [Bug tree-optimization/63464] " jakub at gcc dot gnu.org
2014-10-06 11:52 ` rguenther at suse dot de
2014-10-06 16:59 ` jakub at gcc dot gnu.org
2014-10-07 11:11 ` jakub at gcc dot gnu.org
2014-10-07 11:15 ` rguenther at suse dot de
2014-10-07 20:15 ` glisse at gcc dot gnu.org [this message]
2014-10-07 21:01 ` glisse at gcc dot gnu.org
2014-10-10 12:16 ` jakub at gcc dot gnu.org
2014-10-13 15:51 ` jakub at gcc dot gnu.org
2014-10-13 15:53 ` jakub at gcc dot gnu.org
2014-10-15 14:19 ` jakub at gcc dot gnu.org
2014-10-17 10:55 ` jakub at gcc dot gnu.org
2014-10-17 11:20 ` jakub at gcc dot gnu.org
2014-10-17 11:49 ` ubizjak at gmail dot com
2015-01-16 17:14 ` jakub at gcc dot gnu.org
2015-01-16 17:28 ` jakub at gcc dot gnu.org

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=bug-63464-4-cMH7OOrctw@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).