public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: <apinski@marvell.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <apinski@marvell.com>
Subject: [PATCH 3/4] Factor out removal of write only stores from execute_fixup_cfg
Date: Mon, 18 Oct 2021 21:54:03 -0700	[thread overview]
Message-ID: <1634619244-18969-4-git-send-email-apinski@marvell.com> (raw)
In-Reply-To: <1634619244-18969-1-git-send-email-apinski@marvell.com>

From: Andrew Pinski <apinski@marvell.com>

To make it easier to fix PR 102703, factoring this code out
to its own function makes it easier to read and less indentions
too.

gcc/ChangeLog:

	* tree-cfg.c (maybe_remove_writeonly_store): New function
	factored out from ...
	(execute_fixup_cfg): Here. Call maybe_remove_writeonly_store.
---
 gcc/tree-cfg.c | 62 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 37 insertions(+), 25 deletions(-)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index c20fc4980c6..dbbf6beb6e4 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -9666,6 +9666,38 @@ make_pass_warn_unused_result (gcc::context *ctxt)
   return new pass_warn_unused_result (ctxt);
 }
 
+/* Maybe Remove stores to variables we marked write-only.
+   Return true if a store was removed. */
+static bool
+maybe_remove_writeonly_store (gimple_stmt_iterator &gsi, gimple *stmt)
+{
+  /* Keep access when store has side effect, i.e. in case when source
+     is volatile.  */  
+  if (!gimple_store_p (stmt)
+      || gimple_has_side_effects (stmt)
+      || optimize_debug)
+    return false;
+
+  tree lhs = get_base_address (gimple_get_lhs (stmt));
+
+  if (!VAR_P (lhs)
+      || (!TREE_STATIC (lhs) && !DECL_EXTERNAL (lhs))
+      || !varpool_node::get (lhs)->writeonly)
+    return false;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    {
+      fprintf (dump_file, "Removing statement, writes"
+	       " to write only var:\n");
+      print_gimple_stmt (dump_file, stmt, 0,
+			 TDF_VOPS|TDF_MEMSYMS);
+    }
+  unlink_stmt_vdef (stmt);
+  gsi_remove (&gsi, true);
+  release_defs (stmt);
+  return true;
+}
+
 /* IPA passes, compilation of earlier functions or inlining
    might have changed some properties, such as marked functions nothrow,
    pure, const or noreturn.
@@ -9721,33 +9753,13 @@ execute_fixup_cfg (void)
 		todo |= TODO_cleanup_cfg;
 	     }
 
-	  /* Remove stores to variables we marked write-only.
-	     Keep access when store has side effect, i.e. in case when source
-	     is volatile.  */
-	  if (gimple_store_p (stmt)
-	      && !gimple_has_side_effects (stmt)
-	      && !optimize_debug)
+	  /* Remove stores to variables we marked write-only. */
+	  if (maybe_remove_writeonly_store (gsi, stmt))
 	    {
-	      tree lhs = get_base_address (gimple_get_lhs (stmt));
-
-	      if (VAR_P (lhs)
-		  && (TREE_STATIC (lhs) || DECL_EXTERNAL (lhs))
-		  && varpool_node::get (lhs)->writeonly)
-		{
-		  if (dump_file && (dump_flags & TDF_DETAILS))
-		    {
-		      fprintf (dump_file, "Removing statement, writes"
-		               " to write only var:\n");
-		      print_gimple_stmt (dump_file, stmt, 0,
-					 TDF_VOPS|TDF_MEMSYMS);
-		    }
-		  unlink_stmt_vdef (stmt);
-		  gsi_remove (&gsi, true);
-		  release_defs (stmt);
-	          todo |= TODO_update_ssa | TODO_cleanup_cfg;
-	          continue;
-		}
+	      todo |= TODO_update_ssa | TODO_cleanup_cfg;
+	      continue;
 	    }
+
 	  /* For calls we can simply remove LHS when it is known
 	     to be write-only.  */
 	  if (is_gimple_call (stmt)
-- 
2.17.1


  parent reply	other threads:[~2021-10-19  4:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19  4:54 [PATCH 0/4] Fix PR tree-opt/102703 apinski
2021-10-19  4:54 ` [PATCH 1/4] Add dump prints when execute_fixup_cfg removes a write only var store apinski
2021-10-19 23:10   ` Jeff Law
2021-10-19  4:54 ` [PATCH 2/4] Remove outdated comment about execute_fixup_cfg apinski
2021-10-19 23:10   ` Jeff Law
2021-10-19  4:54 ` apinski [this message]
2021-10-19 23:11   ` [PATCH 3/4] Factor out removal of write only stores from execute_fixup_cfg Jeff Law
2021-10-19  4:54 ` [PATCH 4/4] Improve maybe_remove_writeonly_store to do a simple DCE for defining statement apinski
2021-10-19 23:13   ` Jeff Law
2021-10-20  6:58     ` Richard Biener
2021-10-20 19:53       ` Jeff Law
2021-10-20 19:57         ` Andrew Pinski

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=1634619244-18969-4-git-send-email-apinski@marvell.com \
    --to=apinski@marvell.com \
    --cc=gcc-patches@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).