* [PATCH] tree-object-size: Avoid unnecessary processing of __builtin_object_size
@ 2021-10-18 4:24 Siddhesh Poyarekar
2021-10-18 9:57 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Siddhesh Poyarekar @ 2021-10-18 4:24 UTC (permalink / raw)
To: gcc-patches
This is a minor cleanup to bail out early if the result of
__builtin_object_size is not assigned to anything and avoid initializing
the object size arrays.
gcc/ChangeLog:
* tree-object-size (object_sizes_execute): Consolidate LHS null
check and do it early.
Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
gcc/tree-object-size.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index 6a4dc724f34..46a976dfe10 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -1298,6 +1298,10 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
if (!gimple_call_builtin_p (call, BUILT_IN_OBJECT_SIZE))
continue;
+ tree lhs = gimple_call_lhs (call);
+ if (!lhs)
+ continue;
+
init_object_sizes ();
/* If insert_min_max_p, only attempt to fold
@@ -1312,11 +1316,9 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
{
unsigned HOST_WIDE_INT object_size_type = tree_to_uhwi (ost);
tree ptr = gimple_call_arg (call, 0);
- tree lhs = gimple_call_lhs (call);
if ((object_size_type == 1 || object_size_type == 3)
&& (TREE_CODE (ptr) == ADDR_EXPR
- || TREE_CODE (ptr) == SSA_NAME)
- && lhs)
+ || TREE_CODE (ptr) == SSA_NAME))
{
tree type = TREE_TYPE (lhs);
unsigned HOST_WIDE_INT bytes;
@@ -1339,10 +1341,6 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
continue;
}
- tree lhs = gimple_call_lhs (call);
- if (!lhs)
- continue;
-
result = gimple_fold_stmt_to_constant (call, do_valueize);
if (!result)
{
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tree-object-size: Avoid unnecessary processing of __builtin_object_size
2021-10-18 4:24 [PATCH] tree-object-size: Avoid unnecessary processing of __builtin_object_size Siddhesh Poyarekar
@ 2021-10-18 9:57 ` Richard Biener
2021-10-18 10:12 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2021-10-18 9:57 UTC (permalink / raw)
To: Siddhesh Poyarekar; +Cc: GCC Patches
On Mon, Oct 18, 2021 at 6:25 AM Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
>
> This is a minor cleanup to bail out early if the result of
> __builtin_object_size is not assigned to anything and avoid initializing
> the object size arrays.
OK.
Thanks,
Richard.
> gcc/ChangeLog:
>
> * tree-object-size (object_sizes_execute): Consolidate LHS null
> check and do it early.
>
> Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
> ---
> gcc/tree-object-size.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
> index 6a4dc724f34..46a976dfe10 100644
> --- a/gcc/tree-object-size.c
> +++ b/gcc/tree-object-size.c
> @@ -1298,6 +1298,10 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
> if (!gimple_call_builtin_p (call, BUILT_IN_OBJECT_SIZE))
> continue;
>
> + tree lhs = gimple_call_lhs (call);
> + if (!lhs)
> + continue;
> +
> init_object_sizes ();
>
> /* If insert_min_max_p, only attempt to fold
> @@ -1312,11 +1316,9 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
> {
> unsigned HOST_WIDE_INT object_size_type = tree_to_uhwi (ost);
> tree ptr = gimple_call_arg (call, 0);
> - tree lhs = gimple_call_lhs (call);
> if ((object_size_type == 1 || object_size_type == 3)
> && (TREE_CODE (ptr) == ADDR_EXPR
> - || TREE_CODE (ptr) == SSA_NAME)
> - && lhs)
> + || TREE_CODE (ptr) == SSA_NAME))
> {
> tree type = TREE_TYPE (lhs);
> unsigned HOST_WIDE_INT bytes;
> @@ -1339,10 +1341,6 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
> continue;
> }
>
> - tree lhs = gimple_call_lhs (call);
> - if (!lhs)
> - continue;
> -
> result = gimple_fold_stmt_to_constant (call, do_valueize);
> if (!result)
> {
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tree-object-size: Avoid unnecessary processing of __builtin_object_size
2021-10-18 9:57 ` Richard Biener
@ 2021-10-18 10:12 ` Jakub Jelinek
0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2021-10-18 10:12 UTC (permalink / raw)
To: Richard Biener; +Cc: Siddhesh Poyarekar, GCC Patches
On Mon, Oct 18, 2021 at 11:57:19AM +0200, Richard Biener via Gcc-patches wrote:
> On Mon, Oct 18, 2021 at 6:25 AM Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
> >
> > This is a minor cleanup to bail out early if the result of
> > __builtin_object_size is not assigned to anything and avoid initializing
> > the object size arrays.
>
> OK.
Yeah, fortunately we have expansion for __builtin_object_size so even if
the user tries hard to avoid DCE of the builtin with no LHS through
-fno-tree-dce etc., it shouldn't ICE but expand to -1, 0 or __builtin_trap ()
depending on the arguments it had.
> > gcc/ChangeLog:
> >
> > * tree-object-size (object_sizes_execute): Consolidate LHS null
> > check and do it early.
> >
> > Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-18 10:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18 4:24 [PATCH] tree-object-size: Avoid unnecessary processing of __builtin_object_size Siddhesh Poyarekar
2021-10-18 9:57 ` Richard Biener
2021-10-18 10:12 ` Jakub Jelinek
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).