From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2119) id 54DDA3864867; Sat, 9 Jul 2022 15:11:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54DDA3864867 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jeff Law To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1586] [RFA] Improve initialization of objects when the initializer has trailing zeros. X-Act-Checkin: gcc X-Git-Author: Jeff Law X-Git-Refname: refs/heads/master X-Git-Oldrev: 8f1802003d2b0c516362ea816698317129838bcd X-Git-Newrev: 46dc26fdfbf3e64f82188e21aa6a13ec23108e8e Message-Id: <20220709151147.54DDA3864867@sourceware.org> Date: Sat, 9 Jul 2022 15:11:47 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jul 2022 15:11:47 -0000 https://gcc.gnu.org/g:46dc26fdfbf3e64f82188e21aa6a13ec23108e8e commit r13-1586-g46dc26fdfbf3e64f82188e21aa6a13ec23108e8e Author: Jeff Law 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;