linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memops: kill dead loads before phi-node conversion
@ 2020-11-28 16:50 Luc Van Oostenryck
  0 siblings, 0 replies; only message in thread
From: Luc Van Oostenryck @ 2020-11-28 16:50 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

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


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

only message in thread, other threads:[~2020-11-28 22:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-28 16:50 [PATCH] memops: kill dead loads before phi-node conversion Luc Van Oostenryck

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).