public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Jason Merrill <jason@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH RFA] gimplify: avoid unnecessary copy of init array [PR105838]
Date: Sat, 17 Dec 2022 10:48:33 -0700	[thread overview]
Message-ID: <d2262766-0750-647d-b258-ffdf61b9c26c@gmail.com> (raw)
In-Reply-To: <20221208220112.1700553-1-jason@redhat.com>



On 12/8/22 15:01, Jason Merrill via Gcc-patches wrote:
> After the previous patches, I noticed that we were putting the array of
> strings into .rodata, but then memcpying it into an automatic array, which
> is pointless; we should be able to use it directly.
> 
> C++ doesn't allow us to do this for the backing array of an
> initializer_list, but should be able to do it for the implementation detail
> array we use to construct the backing array.
> 
> This doesn't happen automatically because TREE_ADDRESSABLE is set, and
> gimplify_init_constructor uses that to decide whether to promote a variable
> to static.  Ideally this could use escape analysis to recognize that the
> address, though taken, never leaves the function; that should allow
> promotion when we're only using the address for indexing within the
> function, as in initlist-opt2.C.
> 
> But in initlist-opt1.C, we're passing the array address to another function,
> so it definitely escapes; it's only safe in this case because it's calling a
> standard library function that we know only uses it for indexing.  So, a
> flag seems needed.  I first thought to put the flag on the TARGET_EXPR, but
> the VAR_DECL seems more appropriate.
> 
> Bikeshedding, or other approaches, welcome.
> 
> 	PR c++/105838
> 
> gcc/ChangeLog:
> 
> 	* tree.h (DECL_NOT_OBSERVABLE): New.
> 	* tree-core.h (struct tree_decl_common): Mention it.
> 	* gimplify.cc (gimplify_init_constructor): Check it.
> 
> gcc/cp/ChangeLog:
> 
> 	* call.cc (maybe_init_list_as_array): Set DECL_NOT_OBSERVABLE.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/tree-ssa/initlist-opt1.C: Check for static array.
> 	* g++.dg/tree-ssa/initlist-opt2.C: Likewise.
Presumably the DECL in question isn't actually compiler generated and 
thus DECL_ARTIFICIAL is not appropriate here.  Assuming that's the case, 
should we be setting DECL_NON_OBSERVABLE on VAR_DECLs with 
DECL_ARTIFICIAL set?  I don't think that needs to be done for this patch 
to move forward though.

There haven't been any objections, so OK.


Jeff

  reply	other threads:[~2022-12-17 17:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08 22:01 Jason Merrill
2022-12-17 17:48 ` Jeff Law [this message]
2023-06-02  1:31   ` [PATCH RFA] c++: make initializer_list array static again [PR110070] Jason Merrill
2023-06-02  9:27     ` Richard Biener

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=d2262766-0750-647d-b258-ffdf61b9c26c@gmail.com \
    --to=jeffreyalaw@gmail.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).