linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] kill more dead stores
@ 2021-04-10 22:30 Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 1/5] add testcases for stores simplifications Luc Van Oostenryck
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-04-10 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

This series improv the removal of dead stores:
* kill deadstores in parent-child bascx blocks
* kill redundant in the same basic block

Luc Van Oostenryck (5):
  add testcases for stores simplifications
  extract try_to_kill_store() from kill_dominated_stores()
  volatile stores are never dead
  kill parent's dead stores too
  kill redundant stores (local)

 memops.c                                    | 53 ++++++++++++++++-----
 validation/memops/kill-dead-store-parent0.c | 14 ++++++
 validation/memops/kill-dead-store-parent2.c | 25 ++++++++++
 validation/memops/kill-redundant-store0.c   | 13 +++++
 4 files changed, 94 insertions(+), 11 deletions(-)
 create mode 100644 validation/memops/kill-dead-store-parent0.c
 create mode 100644 validation/memops/kill-dead-store-parent2.c
 create mode 100644 validation/memops/kill-redundant-store0.c


base-commit: d549d4d55eecb394e3f69314287f91e85b19e3e3
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] add testcases for stores simplifications
  2021-04-10 22:30 [PATCH 0/5] kill more dead stores Luc Van Oostenryck
@ 2021-04-10 22:30 ` Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 2/5] extract try_to_kill_store() from kill_dominated_stores() Luc Van Oostenryck
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-04-10 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/memops/kill-dead-store-parent0.c | 15 ++++++++++++
 validation/memops/kill-dead-store-parent2.c | 26 +++++++++++++++++++++
 validation/memops/kill-redundant-store0.c   | 14 +++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 validation/memops/kill-dead-store-parent0.c
 create mode 100644 validation/memops/kill-dead-store-parent2.c
 create mode 100644 validation/memops/kill-redundant-store0.c

diff --git a/validation/memops/kill-dead-store-parent0.c b/validation/memops/kill-dead-store-parent0.c
new file mode 100644
index 000000000000..1413134b8c23
--- /dev/null
+++ b/validation/memops/kill-dead-store-parent0.c
@@ -0,0 +1,15 @@
+void foo(int *ptr, int p)
+{
+	if (p)
+		*ptr = 1;
+	*ptr = 0;
+}
+
+/*
+ * check-name: kill-dead-store-parent0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): store
+ */
diff --git a/validation/memops/kill-dead-store-parent2.c b/validation/memops/kill-dead-store-parent2.c
new file mode 100644
index 000000000000..b563fd31b669
--- /dev/null
+++ b/validation/memops/kill-dead-store-parent2.c
@@ -0,0 +1,26 @@
+int ladder02(int *ptr, int p, int x)
+{
+	*ptr = x++;
+	if (p)
+		goto l11;
+	else
+		goto l12;
+l11:
+	*ptr = x++;
+	goto l20;
+l12:
+	*ptr = x++;
+	goto l20;
+l20:
+	*ptr = x++;
+	return *ptr;
+}
+
+/*
+ * check-name: kill-dead-store-parent2
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): store
+ */
diff --git a/validation/memops/kill-redundant-store0.c b/validation/memops/kill-redundant-store0.c
new file mode 100644
index 000000000000..e911166dd953
--- /dev/null
+++ b/validation/memops/kill-redundant-store0.c
@@ -0,0 +1,14 @@
+void foo(int *ptr)
+{
+	int i = *ptr;
+	*ptr = i;
+}
+
+/*
+ * check-name: kill-redundant-store0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: store
+ */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] extract try_to_kill_store() from kill_dominated_stores()
  2021-04-10 22:30 [PATCH 0/5] kill more dead stores Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 1/5] add testcases for stores simplifications Luc Van Oostenryck
@ 2021-04-10 22:30 ` Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 3/5] volatile stores are never dead Luc Van Oostenryck
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-04-10 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Move the test/replace part of the store simplification in a
separate function so that it can be reused.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 memops.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/memops.c b/memops.c
index ff54208e2d54..31fd2d3eaffc 100644
--- a/memops.c
+++ b/memops.c
@@ -204,6 +204,23 @@ next_load:
 	} END_FOR_EACH_PTR_REVERSE(insn);
 }
 
+static bool try_to_kill_store(pseudo_t pseudo, struct instruction *insn,
+			     struct instruction *dom, int local)
+{
+	int dominance = dominates(pseudo, insn, dom, local);
+
+	if (dominance) {
+		/* possible partial dominance? */
+		if (dominance < 0)
+			return false;
+		if (dom->opcode == OP_LOAD)
+			return false;
+		/* Yeehaa! Found one! */
+		kill_instruction_force(dom);
+	}
+	return true;
+}
+
 static void kill_dominated_stores(struct basic_block *bb)
 {
 	struct instruction *insn;
@@ -223,19 +240,10 @@ static void kill_dominated_stores(struct basic_block *bb)
 
 			local = local_pseudo(pseudo);
 			RECURSE_PTR_REVERSE(insn, dom) {
-				int dominance;
 				if (!dom->bb)
 					continue;
-				dominance = dominates(pseudo, insn, dom, local);
-				if (dominance) {
-					/* possible partial dominance? */
-					if (dominance < 0)
-						goto next_store;
-					if (dom->opcode == OP_LOAD)
-						goto next_store;
-					/* Yeehaa! Found one! */
-					kill_instruction_force(dom);
-				}
+				if (!try_to_kill_store(pseudo, insn, dom, local))
+					goto next_store;
 			} END_FOR_EACH_PTR_REVERSE(dom);
 
 			/* OK, we should check the parents now */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] volatile stores are never dead
  2021-04-10 22:30 [PATCH 0/5] kill more dead stores Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 1/5] add testcases for stores simplifications Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 2/5] extract try_to_kill_store() from kill_dominated_stores() Luc Van Oostenryck
@ 2021-04-10 22:30 ` Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 4/5] kill parent's dead stores too Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 5/5] kill redundant stores (local) Luc Van Oostenryck
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-04-10 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

so they shouldn't be killed.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 memops.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/memops.c b/memops.c
index 31fd2d3eaffc..8020f2e6cf03 100644
--- a/memops.c
+++ b/memops.c
@@ -215,6 +215,8 @@ static bool try_to_kill_store(pseudo_t pseudo, struct instruction *insn,
 			return false;
 		if (dom->opcode == OP_LOAD)
 			return false;
+		if (dom->is_volatile)
+			return false;
 		/* Yeehaa! Found one! */
 		kill_instruction_force(dom);
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] kill parent's dead stores too
  2021-04-10 22:30 [PATCH 0/5] kill more dead stores Luc Van Oostenryck
                   ` (2 preceding siblings ...)
  2021-04-10 22:30 ` [PATCH 3/5] volatile stores are never dead Luc Van Oostenryck
@ 2021-04-10 22:30 ` Luc Van Oostenryck
  2021-04-10 22:30 ` [PATCH 5/5] kill redundant stores (local) Luc Van Oostenryck
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-04-10 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

kill_dominated_stores() identify and remove dead stores
(stores unneeded because the same location is overwritten later
by another store) only when both stores are in the same basic block.

Slightly improve this by also handling the case when the dead store
is in a parent BB of the "live" store.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 memops.c                                    | 16 ++++++++++++++++
 validation/memops/kill-dead-store-parent0.c |  1 -
 validation/memops/kill-dead-store-parent2.c |  1 -
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/memops.c b/memops.c
index 8020f2e6cf03..44d90754d279 100644
--- a/memops.c
+++ b/memops.c
@@ -231,6 +231,7 @@ static void kill_dominated_stores(struct basic_block *bb)
 		if (!insn->bb)
 			continue;
 		if (insn->opcode == OP_STORE) {
+			struct basic_block *par;
 			struct instruction *dom;
 			pseudo_t pseudo = insn->src;
 			int local;
@@ -249,6 +250,21 @@ static void kill_dominated_stores(struct basic_block *bb)
 			} END_FOR_EACH_PTR_REVERSE(dom);
 
 			/* OK, we should check the parents now */
+			FOR_EACH_PTR(bb->parents, par) {
+
+				if (bb_list_size(par->children) != 1)
+					goto next_parent;
+				FOR_EACH_PTR(par->insns, dom) {
+					if (!dom->bb)
+						continue;
+					if (dom == insn)
+						goto next_parent;
+					if (!try_to_kill_store(pseudo, insn, dom, local))
+						goto next_parent;
+				} END_FOR_EACH_PTR(dom);
+next_parent:
+				;
+			} END_FOR_EACH_PTR(par);
 		}
 next_store:
 		/* Do the next one */;
diff --git a/validation/memops/kill-dead-store-parent0.c b/validation/memops/kill-dead-store-parent0.c
index 1413134b8c23..c1b2466ca450 100644
--- a/validation/memops/kill-dead-store-parent0.c
+++ b/validation/memops/kill-dead-store-parent0.c
@@ -8,7 +8,6 @@ void foo(int *ptr, int p)
 /*
  * check-name: kill-dead-store-parent0
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-pattern(1): store
diff --git a/validation/memops/kill-dead-store-parent2.c b/validation/memops/kill-dead-store-parent2.c
index b563fd31b669..4f7b9dd901d9 100644
--- a/validation/memops/kill-dead-store-parent2.c
+++ b/validation/memops/kill-dead-store-parent2.c
@@ -19,7 +19,6 @@ l20:
 /*
  * check-name: kill-dead-store-parent2
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-pattern(1): store
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] kill redundant stores (local)
  2021-04-10 22:30 [PATCH 0/5] kill more dead stores Luc Van Oostenryck
                   ` (3 preceding siblings ...)
  2021-04-10 22:30 ` [PATCH 4/5] kill parent's dead stores too Luc Van Oostenryck
@ 2021-04-10 22:30 ` Luc Van Oostenryck
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-04-10 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

A store is called 'redundant' when the corresponding location
already contains the value that will be stored.

This patch removes such stores in the case where the memops
which make them redundant is in the same basic block.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 memops.c                                  | 5 +++++
 validation/memops/kill-redundant-store0.c | 1 -
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/memops.c b/memops.c
index 44d90754d279..f734f6eb7398 100644
--- a/memops.c
+++ b/memops.c
@@ -213,6 +213,11 @@ static bool try_to_kill_store(pseudo_t pseudo, struct instruction *insn,
 		/* possible partial dominance? */
 		if (dominance < 0)
 			return false;
+		if (insn->target == dom->target && insn->bb == dom->bb) {
+			// found a memop which makes the store redundant
+			kill_instruction_force(insn);
+			return false;
+		}
 		if (dom->opcode == OP_LOAD)
 			return false;
 		if (dom->is_volatile)
diff --git a/validation/memops/kill-redundant-store0.c b/validation/memops/kill-redundant-store0.c
index e911166dd953..8819938fe763 100644
--- a/validation/memops/kill-redundant-store0.c
+++ b/validation/memops/kill-redundant-store0.c
@@ -7,7 +7,6 @@ void foo(int *ptr)
 /*
  * check-name: kill-redundant-store0
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: store
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-10 22:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-10 22:30 [PATCH 0/5] kill more dead stores Luc Van Oostenryck
2021-04-10 22:30 ` [PATCH 1/5] add testcases for stores simplifications Luc Van Oostenryck
2021-04-10 22:30 ` [PATCH 2/5] extract try_to_kill_store() from kill_dominated_stores() Luc Van Oostenryck
2021-04-10 22:30 ` [PATCH 3/5] volatile stores are never dead Luc Van Oostenryck
2021-04-10 22:30 ` [PATCH 4/5] kill parent's dead stores too Luc Van Oostenryck
2021-04-10 22:30 ` [PATCH 5/5] kill redundant stores (local) 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).