public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6661] Remove variables only used with .DEFERRED_INIT
@ 2023-03-14 12:46 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-03-14 12:46 UTC (permalink / raw)
  To: gcc-cvs

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

commit r13-6661-gbd6e566e9dc543cf4f6df69dcefb40bb8b4100f1
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Mar 14 09:42:45 2023 +0100

    Remove variables only used with .DEFERRED_INIT
    
    In PR109087 it was noticed that we rely on DSE to remove .DEFERRED_INIT
    when it is the only remaining use of a variable.  Since DSE is imperfect
    and even if it were not would be limited by the amount of statements to
    walk the following enhances the unused var removal pass to handle
    .DEFERRED_INIT like CLOBBERs, thus we do not keep local variables just
    because they are deferred initialized.
    
            * tree-ssa-live.cc (remove_unused_locals): Do not treat
            the .DEFERRED_INIT of a variable as use, instead remove
            that if it is the only use.
    
            * gcc.dg/auto-init-unused-1.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/auto-init-unused-1.c | 16 ++++++++++++++++
 gcc/tree-ssa-live.cc                      | 21 ++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/auto-init-unused-1.c b/gcc/testsuite/gcc.dg/auto-init-unused-1.c
new file mode 100644
index 00000000000..b7d44e6b4f2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/auto-init-unused-1.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -ftrivial-auto-var-init=zero -fdump-tree-ssa" } */
+
+int a;
+int foo (void);
+int bar (void);
+
+void
+baz (void)
+{
+  int *b[6];
+  if (foo ())
+    a |= bar ();
+}
+
+/* { dg-final { scan-tree-dump-not "DEFERRED_INIT" "ssa" } } */
diff --git a/gcc/tree-ssa-live.cc b/gcc/tree-ssa-live.cc
index c179444e8e1..9118e82b4f1 100644
--- a/gcc/tree-ssa-live.cc
+++ b/gcc/tree-ssa-live.cc
@@ -813,6 +813,12 @@ remove_unused_locals (void)
 	      continue;
 	    }
 
+	  if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
+	    {
+	      have_local_clobbers = true;
+	      continue;
+	    }
+
 	  if (b)
 	    TREE_USED (b) = true;
 
@@ -856,7 +862,7 @@ remove_unused_locals (void)
      to remove them if they are the only references to a local variable,
      but we want to retain them when there's any other.  So the first pass
      ignores them, and the second pass (if there were any) tries to remove
-     them.  */
+     them.  We do the same for .DEFERRED_INIT.  */
   if (have_local_clobbers)
     FOR_EACH_BB_FN (bb, cfun)
       {
@@ -888,6 +894,19 @@ remove_unused_locals (void)
 		if (b)
 		  TREE_USED (b) = true;
 	      }
+	    else if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
+	      {
+		tree lhs = gimple_call_lhs (stmt);
+		if (DECL_P (lhs) && !is_used_p (lhs))
+		  {
+		    unlink_stmt_vdef (stmt);
+		    gsi_remove (&gsi, true);
+		    release_defs (stmt);
+		    continue;
+		  }
+		if (b)
+		  TREE_USED (b) = true;
+	      }
 	    else if (gimple_debug_bind_p (stmt))
 	      {
 		tree var = gimple_debug_bind_get_var (stmt);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-14 12:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 12:46 [gcc r13-6661] Remove variables only used with .DEFERRED_INIT 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).