From: Aldy Hernandez <aldyh@redhat.com>
To: Jason Merrill <jason@redhat.com>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [patch] Optimize empty class copies within a C++ return statement
Date: Mon, 09 Mar 2015 18:33:00 -0000 [thread overview]
Message-ID: <54FDE762.6040409@redhat.com> (raw)
In-Reply-To: <54FA23D7.3030301@redhat.com>
On 03/06/2015 02:01 PM, Jason Merrill wrote:
> On 03/06/2015 05:01 PM, Jason Merrill wrote:
>> On 03/06/2015 04:54 PM, Aldy Hernandez wrote:
>>>> But doesn't this still involve a MODIFY_EXPR, i.e. return retval =
>>>> D.2349?
>>>
>>> If I understand you correct, no.
>>>
>>> gimplify_return_expr creates a new temporary and uses that instead of
>>> <retval>:
>>>
>>> else if (gimplify_ctxp->return_temp)
>>> result = gimplify_ctxp->return_temp;
>>> else
>>> {
>>> result = create_tmp_reg (TREE_TYPE (result_decl));
>>> ...
>>> }
>>> ...
>>> ...
>>> /* Smash the lhs of the MODIFY_EXPR to the temporary we plan to use.
>>> Then gimplify the whole thing. */
>>> if (result != result_decl)
>>> TREE_OPERAND (ret_expr, 0) = result;
>>
>> Sounds like ret_expr is a MODIFY_EXPR.
>
> Oh, but with the wrong lhs, I see.
I know you want to reuse the MODIFY_EXPR case in cp_gimplify_expr, but
after playing around with it, I think it requires too much special
casing to make it clean.
For instance, the MODIFY_EXPR case returns the RHS of expression which
is the opposite of what we want. For this:
return retval = <obj>
...the MODIFY_EXPR case would build a COMPOUND_EXPR with "return
<<<retval, <obj>>>>", which would return <obj>, not retval. And what we
probably want is a statement list with:
<evaluation of obj>
return retval
Also, the actual case we're dealing with here is a bit more
complicated, as it involves a COMPOUND_EXPR in the RHS, which we'd have
to adapt MODIFY_EXPR to handle:
return retval = <<<TARGET_EXPR, D.9999>>
IMHO, adding a special case for all this is a lot messier than what I
originally suggested.
What do you think?
Aldy
next prev parent reply other threads:[~2015-03-09 18:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-05 23:25 Aldy Hernandez
2015-03-06 6:20 ` Jason Merrill
2015-03-06 16:19 ` Aldy Hernandez
2015-03-06 21:46 ` Jason Merrill
2015-03-06 21:54 ` Aldy Hernandez
2015-03-06 22:01 ` Jason Merrill
2015-03-06 22:02 ` Jason Merrill
2015-03-09 18:33 ` Aldy Hernandez [this message]
2015-03-10 2:51 ` Jason Merrill
2015-03-10 23:11 ` Aldy Hernandez
2015-03-10 23:59 ` Jason Merrill
2015-03-11 0:07 ` Aldy Hernandez
2015-03-11 0:55 ` Jason Merrill
2015-03-11 1:45 ` Aldy Hernandez
2015-03-11 12:06 ` Jason Merrill
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=54FDE762.6040409@redhat.com \
--to=aldyh@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.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).