This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/84029] Partially inline strcmp
- From: "wilco at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 25 Jan 2018 15:46:19 +0000
- Subject: [Bug middle-end/84029] Partially inline strcmp
- Auto-submitted: auto-generated
- References: <bug-84029-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84029
--- Comment #2 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> If we know the length of either argument and the other argument is properly
> aligned we can do a 2, 4 or 8 byte compare upfront. Not sure how often that
> happens (esp. with regard to knowing alignment to make sure there's no
> page fault).
Yes that is another optimization related to PR78809 where you could do multiple
characters in one go when you know alignment (one of the strings must be a
constant string as otherwise equality doesn't work).
> Note this optimization has a code-size impact and thus should be done only
> for hot code regions, eventually based on a value-profile?
If codesize impact is significant it could be -O3 only. However there are not
that many uses of strcmp in most applications, so if the gain is large (think
naive code comparing an input string against a set of keywords like in
glibc/argp/argp-parse.c), it may be worth it with -O2.