diff mbox series

memops: kill dead loads before phi-node conversion

Message ID 20201128165025.19323-1-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series memops: kill dead loads before phi-node conversion | expand

Commit Message

Luc Van Oostenryck Nov. 28, 2020, 4:50 p.m. UTC
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 mbox series

Patch

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
+ */