linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH] memops: kill dead loads before phi-node conversion
Date: Sat, 28 Nov 2020 17:50:25 +0100	[thread overview]
Message-ID: <20201128165025.19323-1-luc.vanoostenryck@gmail.com> (raw)

During load simplification it may happen that a load is unused
but if this fact is ignored and the usual conversion to a phi-node
is node, then this value may seem to be needed and can't be anymore
be simplified away.

Fix this by removing dead loads during load simplification.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 memops.c                              |  5 +++++
 validation/memops/kill-dead-loads00.c | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 validation/memops/kill-dead-loads00.c

diff --git a/memops.c b/memops.c
index badcdbbb9378..6baf4d163b00 100644
--- a/memops.c
+++ b/memops.c
@@ -111,6 +111,11 @@ static void simplify_loads(struct basic_block *bb)
 			if (insn->is_volatile)
 				continue;
 
+			if (!has_users(insn->target)) {
+				kill_instruction(insn);
+				continue;
+			}
+
 			RECURSE_PTR_REVERSE(insn, dom) {
 				int dominance;
 				if (!dom->bb)
diff --git a/validation/memops/kill-dead-loads00.c b/validation/memops/kill-dead-loads00.c
new file mode 100644
index 000000000000..df7ec037e2f2
--- /dev/null
+++ b/validation/memops/kill-dead-loads00.c
@@ -0,0 +1,22 @@
+void fun(void);
+
+void foo(int *p)
+{
+	for (*p; *p; *p) {
+l:
+		fun();
+	}
+
+	if (0)
+		goto l;
+}
+
+/*
+ * check-name: kill-dead-loads00
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: phi\\.
+ * check-output-pattern(1): load\\.
+ * check-output-end
+ */
-- 
2.29.2


                 reply	other threads:[~2020-11-28 22:06 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=20201128165025.19323-1-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.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 NNTP newsgroup(s).