* [RFA] Improve initialization of objects when the initializer has trailing zeros.
@ 2022-07-07 14:46 Jeff Law
2022-07-08 0:06 ` Takayuki 'January June' Suwa
2022-07-08 7:11 ` Richard Biener
0 siblings, 2 replies; 3+ messages in thread
From: Jeff Law @ 2022-07-07 14:46 UTC (permalink / raw)
To: 'GCC Patches'
[-- Attachment #1: Type: text/plain, Size: 990 bytes --]
This is an update to a patch originally posted by Takayuki Suwa a few
months ago.
When we initialize an array from a STRING_CST we perform the
initialization in two steps. The first step copies the STRING_CST to
the destination. The second step uses clear_storage to initialize
storage in the array beyond TREE_STRING_LENGTH of the initializer.
Takayuki's patch added a special case when the STRING_CST itself was all
zeros which would avoid the copy from the STRING_CST and instead do all
the initialization via clear_storage which is clearly more runtime
efficient.
Richie had the suggestion that instead of special casing when the entire
STRING_CST was NULs to instead identify when the tail of the STRING_CST
was NULs. That's more general and handles Takayuki's case as well.
Bootstrapped and regression tested on x86_64-linux-gnu. Given I rewrote
Takayuki's patch I think it needs someone else to review rather than
self-approving.
OK for the trunk?
Jeff
[-- Attachment #2: P --]
[-- Type: text/plain, Size: 819 bytes --]
* 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 --git a/gcc/expr.cc b/gcc/expr.cc
index 62297379ec9..f94d46b969c 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -6087,6 +6087,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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Improve initialization of objects when the initializer has trailing zeros.
2022-07-07 14:46 [RFA] Improve initialization of objects when the initializer has trailing zeros Jeff Law
@ 2022-07-08 0:06 ` Takayuki 'January June' Suwa
2022-07-08 7:11 ` Richard Biener
1 sibling, 0 replies; 3+ messages in thread
From: Takayuki 'January June' Suwa @ 2022-07-08 0:06 UTC (permalink / raw)
To: Jeff Law; +Cc: GCC Patches
On 2022/07/07 23:46, Jeff Law wrote:
> This is an update to a patch originally posted by Takayuki Suwa a few months ago.
>
> When we initialize an array from a STRING_CST we perform the initialization in two steps. The first step copies the STRING_CST to the destination. The second step uses clear_storage to initialize storage in the array beyond TREE_STRING_LENGTH of the initializer.
>
> Takayuki's patch added a special case when the STRING_CST itself was all zeros which would avoid the copy from the STRING_CST and instead do all the initialization via clear_storage which is clearly more runtime efficient.
Thank you for understanding what I mean...
> Richie had the suggestion that instead of special casing when the entire STRING_CST was NULs to instead identify when the tail of the STRING_CST was NULs. That's more general and handles Takayuki's case as well.
and offering good explanation.
> Bootstrapped and regression tested on x86_64-linux-gnu. Given I rewrote Takayuki's patch I think it needs someone else to review rather than self-approving.
LGTM and of course it resolves the beginning of the first place (https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595685.html).
>
> OK for the trunk?
>
> Jeff
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Improve initialization of objects when the initializer has trailing zeros.
2022-07-07 14:46 [RFA] Improve initialization of objects when the initializer has trailing zeros Jeff Law
2022-07-08 0:06 ` Takayuki 'January June' Suwa
@ 2022-07-08 7:11 ` Richard Biener
1 sibling, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-07-08 7:11 UTC (permalink / raw)
To: Jeff Law; +Cc: GCC Patches
On Thu, Jul 7, 2022 at 4:46 PM Jeff Law via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This is an update to a patch originally posted by Takayuki Suwa a few
> months ago.
>
> When we initialize an array from a STRING_CST we perform the
> initialization in two steps. The first step copies the STRING_CST to
> the destination. The second step uses clear_storage to initialize
> storage in the array beyond TREE_STRING_LENGTH of the initializer.
>
> Takayuki's patch added a special case when the STRING_CST itself was all
> zeros which would avoid the copy from the STRING_CST and instead do all
> the initialization via clear_storage which is clearly more runtime
> efficient.
>
> Richie had the suggestion that instead of special casing when the entire
> STRING_CST was NULs to instead identify when the tail of the STRING_CST
> was NULs. That's more general and handles Takayuki's case as well.
>
> Bootstrapped and regression tested on x86_64-linux-gnu. Given I rewrote
> Takayuki's patch I think it needs someone else to review rather than
> self-approving.
>
> OK for the trunk?
OK.
Thanks,
Richard.
> Jeff
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-08 7:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07 14:46 [RFA] Improve initialization of objects when the initializer has trailing zeros Jeff Law
2022-07-08 0:06 ` Takayuki 'January June' Suwa
2022-07-08 7:11 ` Richard Biener
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).