public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/62156] memcmp doesn't see through memcpy at compile-time
Date: Tue, 19 Aug 2014 11:19:00 -0000 [thread overview]
Message-ID: <bug-62156-4-jMKHstnS7U@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-62156-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62156
--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 19 Aug 2014, glisse at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62156
>
> --- Comment #5 from Marc Glisse <glisse at gcc dot gnu.org> ---
> (In reply to rguenther@suse.de from comment #4)
> > Eventually worth "fixing" the libstdc++ side to generate better
> > initial code?
>
> Replacing memcpy(,,3)+assign(,'\0') with memcpy(,,4) can indeed be done at the
> libstdc++ level (although simplify_builtin_call in tree-ssa-forwprop.c already
> does a transformation extremely similar and could be extended). As shown in
> comment #3, the test/jump will disappear when we move to C++11.
>
> But essentially, it can't avoid doing memcpy, setting the length of the string,
> and calling memcmp.
>
> One surprising thing it does not is, at the beginning of operator==, check if
> the sizes are the same before calling memcmp...
>
> > Other than that it seems this would need careful special-handling
> > in value-numbering ...
>
> That seems like the best place indeed.
>
> > not sure if optimizing std::string("foo") == "bar" is important.
>
> The question is how many other optimizations this would enable. I remember
> other cases where we couldn't see through memcpy well enough (PR 58483 for
> instance, there were others probably more relevant), but I don't know if this
> would help them.
>
> In any case, I agree this isn't a priority.
The special thing with memcmp is that it evaluates to a value
we'd like to compute while the usual look-through-memcpy is
for value-numbering loads.
So it won't be that easy...
IMHO it would be nicer if we'd fix PR52171 which should be able
to catch your simple case then via existing value-numbering code
at least if the compare includes the trailing zero.
prev parent reply other threads:[~2014-08-19 11:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-15 11:36 [Bug tree-optimization/62156] New: " glisse at gcc dot gnu.org
2014-08-18 14:06 ` [Bug tree-optimization/62156] " rguenth at gcc dot gnu.org
2014-08-18 14:47 ` glisse at gcc dot gnu.org
2014-08-18 15:19 ` glisse at gcc dot gnu.org
2014-08-19 8:02 ` rguenther at suse dot de
2014-08-19 11:15 ` glisse at gcc dot gnu.org
2014-08-19 11:19 ` rguenther at suse dot de [this message]
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-62156-4-jMKHstnS7U@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).