]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-object-size: Avoid unnecessary processing of __builtin_object_size
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 18 Oct 2021 03:45:42 +0000 (09:15 +0530)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 18 Oct 2021 13:34:16 +0000 (19:04 +0530)
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.c (object_sizes_execute): Consolidate LHS
null check and do it early.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/tree-object-size.c

index 6a4dc724f34ec9fc9961a912a49d3494f97f5f81..46a976dfe107dff358ca9ee76b6fb5e1b711cdb8 100644 (file)
@@ -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)
            {