public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7201] middle-end: Small __builtin_clear_padding improvements
Date: Fri, 11 Feb 2022 18:47:56 +0000 (GMT)	[thread overview]
Message-ID: <20220211184756.57376385841B@sourceware.org> (raw)

https://gcc.gnu.org/g:b56ad95854f0b007afda60c057f10b04666953c9

commit r12-7201-gb56ad95854f0b007afda60c057f10b04666953c9
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Feb 11 19:47:14 2022 +0100

    middle-end: Small __builtin_clear_padding improvements
    
    When looking at __builtin_clear_padding today, I've noticed that
    it is quite wasteful to extend the original user one argument to 3,
    2 is enough.  We need to encode the original type of the first argument
    because pointer conversions are useless in GIMPLE, and we need to record
    a boolean whether it is for -ftrivial-auto-var-init=* or not.
    But for recording the type we don't need the value (we've always used
    zero) and for recording the boolean we don't need the type (we've always
    used integer_type_node).
    So, this patch merges the two into one.
    
    2022-02-11  Jakub Jelinek  <jakub@redhat.com>
    
            * tree.cc (build_common_builtin_nodes): Fix up formatting in
            __builtin_clear_padding decl creation.
            * gimplify.cc (gimple_add_padding_init_for_auto_var): Encode
            for_auto_init in the value of 2nd BUILT_IN_CLEAR_PADDING
            argument rather than in 3rd argument.
            (gimplify_call_expr): Likewise.  Fix up comment formatting.
            * gimple-fold.cc (gimple_fold_builtin_clear_padding): Expect
            2 arguments instead of 3, take for_auto_init from the value
            of 2nd argument.

Diff:
---
 gcc/gimple-fold.cc | 10 +++++-----
 gcc/gimplify.cc    | 19 ++++++-------------
 gcc/tree.cc        |  2 +-
 3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 9e0c01d6353..d9b1a442a7a 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -4876,13 +4876,13 @@ static bool
 gimple_fold_builtin_clear_padding (gimple_stmt_iterator *gsi)
 {
   gimple *stmt = gsi_stmt (*gsi);
-  gcc_assert (gimple_call_num_args (stmt) == 3);
+  gcc_assert (gimple_call_num_args (stmt) == 2);
   tree ptr = gimple_call_arg (stmt, 0);
   tree typearg = gimple_call_arg (stmt, 1);
-  /* the 3rd argument of __builtin_clear_padding is to distinguish whether
-     this call is made by the user or by the compiler for automatic variable
-     initialization.  */
-  bool for_auto_init = (bool) TREE_INT_CST_LOW (gimple_call_arg (stmt, 2));
+  /* The 2nd argument of __builtin_clear_padding's value is used to
+     distinguish whether this call is made by the user or by the compiler
+     for automatic variable initialization.  */
+  bool for_auto_init = (bool) TREE_INT_CST_LOW (typearg);
   tree type = TREE_TYPE (TREE_TYPE (typearg));
   location_t loc = gimple_location (stmt);
   clear_padding_struct buf;
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 8d676fb96c8..7d8850e53ec 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -1804,7 +1804,6 @@ gimple_add_padding_init_for_auto_var (tree decl, bool is_vla,
 				      gimple_seq *seq_p)
 {
   tree addr_of_decl = NULL_TREE;
-  bool for_auto_init = true;
   tree fn = builtin_decl_explicit (BUILT_IN_CLEAR_PADDING);
 
   if (is_vla)
@@ -1821,11 +1820,8 @@ gimple_add_padding_init_for_auto_var (tree decl, bool is_vla,
       addr_of_decl = build_fold_addr_expr (decl);
     }
 
-  gimple *call = gimple_build_call (fn,
-				    3, addr_of_decl,
-				    build_zero_cst (TREE_TYPE (addr_of_decl)),
-				    build_int_cst (integer_type_node,
-						   (int) for_auto_init));
+  gimple *call = gimple_build_call (fn, 2, addr_of_decl,
+				    build_one_cst (TREE_TYPE (addr_of_decl)));
   gimplify_seq_add_stmt (seq_p, call);
 }
 
@@ -3536,15 +3532,12 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
 	  {
 	    /* Remember the original type of the argument in an internal
 	       dummy second argument, as in GIMPLE pointer conversions are
-	       useless. also mark this call as not for automatic initialization
-	       in the internal dummy third argument.  */
+	       useless.  Also mark this call as not for automatic
+	       initialization in the internal dummy third argument.  */
 	    p = CALL_EXPR_ARG (*expr_p, 0);
-	    bool for_auto_init = false;
 	    *expr_p
-	      = build_call_expr_loc (EXPR_LOCATION (*expr_p), fndecl, 3, p,
-				     build_zero_cst (TREE_TYPE (p)),
-				     build_int_cst (integer_type_node,
-						    (int) for_auto_init));
+	      = build_call_expr_loc (EXPR_LOCATION (*expr_p), fndecl, 2, p,
+				     build_zero_cst (TREE_TYPE (p)));
 	    return GS_OK;
 	  }
 	break;
diff --git a/gcc/tree.cc b/gcc/tree.cc
index aeb3b4cebcf..dd919ff0717 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -9520,7 +9520,7 @@ build_common_builtin_nodes (void)
       local_define_builtin ("__builtin_clear_padding", ftype,
 			    BUILT_IN_CLEAR_PADDING,
 			    "__builtin_clear_padding",
-			      ECF_LEAF | ECF_NOTHROW);
+			    ECF_LEAF | ECF_NOTHROW);
     }
 
   if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)


                 reply	other threads:[~2022-02-11 18:47 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=20220211184756.57376385841B@sourceware.org \
    --to=jakub@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).