public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jeff Law <law@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1586] [RFA] Improve initialization of objects when the initializer has trailing zeros.
Date: Sat,  9 Jul 2022 15:11:47 +0000 (GMT)	[thread overview]
Message-ID: <20220709151147.54DDA3864867@sourceware.org> (raw)

https://gcc.gnu.org/g:46dc26fdfbf3e64f82188e21aa6a13ec23108e8e

commit r13-1586-g46dc26fdfbf3e64f82188e21aa6a13ec23108e8e
Author: Jeff Law <jeffreyalaw@gmail.com>
Date:   Sat Jul 9 11:11:00 2022 -0400

    [RFA] Improve initialization of objects when the initializer has trailing zeros.
    
    gcc/
    
            * expr.cc (store_expr): Identify trailing NULs in a STRING_CST
            initializer and use clear_storage rather than copying the
            NULs to the destination array.

Diff:
---
 gcc/expr.cc | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index eb280e6cac3..f9753d48245 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -6088,6 +6088,17 @@ store_expr (tree exp, rtx target, int call_param_p,
 	}
 
       str_copy_len = TREE_STRING_LENGTH (str);
+
+      /* Trailing NUL bytes in EXP will be handled by the call to
+	 clear_storage, which is more efficient than copying them from
+	 the STRING_CST, so trim those from STR_COPY_LEN.  */
+      while (str_copy_len)
+	{
+	  if (TREE_STRING_POINTER (str)[str_copy_len - 1])
+	    break;
+	  str_copy_len--;
+	}
+
       if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0)
 	{
 	  str_copy_len += STORE_MAX_PIECES - 1;


                 reply	other threads:[~2022-07-09 15:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220709151147.54DDA3864867@sourceware.org \
    --to=law@gcc.gnu.org \
    --cc=gcc-cvs@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).