public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/109139 - fix .DEFERRED_INIT removal
Date: Wed, 15 Mar 2023 09:29:15 +0000 (UTC)	[thread overview]
Message-ID: <20230315092915.CALlIwtZONEo8LNURyIROISNInlA113A7UDAFnUG1LQ@z> (raw)

The following make sure to strip MEMs when looking for unused
decls on the LHS of .DEFERRED_INIT.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/109139
	* tree-ssa-live.cc (remove_unused_locals): Look at the
	base address for unused decls on the LHS of .DEFERRED_INIT.

	* gcc.dg/torture/pr109139.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr109139.c | 12 ++++++++++++
 gcc/tree-ssa-live.cc                    |  3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr109139.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr109139.c b/gcc/testsuite/gcc.dg/torture/pr109139.c
new file mode 100644
index 00000000000..9fa97ebc665
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr109139.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */
+
+const int COMPARE_CANDIDATE;
+char ipmi_ek_compare_link_record1_0, ipmi_ek_compare_link_record2_0;
+void ipmi_ek_compare_link()
+{
+  for (; ipmi_ek_compare_link_record1_0;)
+    for (; ipmi_ek_compare_link_record2_0;) {
+	int link[COMPARE_CANDIDATE];
+    }
+}
diff --git a/gcc/tree-ssa-live.cc b/gcc/tree-ssa-live.cc
index 9118e82b4f1..1be92956cc5 100644
--- a/gcc/tree-ssa-live.cc
+++ b/gcc/tree-ssa-live.cc
@@ -897,7 +897,8 @@ remove_unused_locals (void)
 	    else if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
 	      {
 		tree lhs = gimple_call_lhs (stmt);
-		if (DECL_P (lhs) && !is_used_p (lhs))
+		tree base = get_base_address (lhs);
+		if (DECL_P (base) && !is_used_p (base))
 		  {
 		    unlink_stmt_vdef (stmt);
 		    gsi_remove (&gsi, true);
-- 
2.35.3

                 reply	other threads:[~2023-03-15  9:29 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=20230315092915.CALlIwtZONEo8LNURyIROISNInlA113A7UDAFnUG1LQ@z \
    --to=rguenther@suse.de \
    --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).