All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] teach memory simplification about ASM instructions
@ 2021-02-21 22:34 Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 1/5] reorg dominates() Luc Van Oostenryck
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-02-21 22:34 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

This series fixes simplify_memops() which didn't took in account the
fact that ASM instructions can also modify the content of the memory:
either because it contains an output memory operand, or because
it explicetly clobbers memory in some other way.

Luc Van Oostenryck (5):
  reorg dominates()
  asm-mem: add testcase for missing reload after asm memops
  asm-mem: does it clobber memory?
  asm-mem: does it output to memory?
  asm-mem: teach dominates() about OP_ASM

 flow.c                           | 17 +++++++++++++----
 linearize.c                      |  9 ++++++++-
 linearize.h                      |  2 ++
 validation/mem2reg/asm-reload0.c | 14 ++++++++++++++
 4 files changed, 37 insertions(+), 5 deletions(-)
 create mode 100644 validation/mem2reg/asm-reload0.c


base-commit: 2494587e823700458923052b17b0b981be92d776
-- 
2.30.0


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

* [PATCH 1/5] reorg dominates()
  2021-02-21 22:34 [PATCH 0/5] teach memory simplification about ASM instructions Luc Van Oostenryck
@ 2021-02-21 22:34 ` Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 2/5] asm-mem: add testcase for missing reload after asm memops Luc Van Oostenryck
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-02-21 22:34 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

To prepare the handling of OP_ASM instructions, reorganize the
opcode tests to use a switch.

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

diff --git a/flow.c b/flow.c
index bda277aa551b..5751ce756518 100644
--- a/flow.c
+++ b/flow.c
@@ -490,12 +490,15 @@ static inline int distinct_symbols(pseudo_t a, pseudo_t b)
  */
 int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom, int local)
 {
-	int opcode = dom->opcode;
-
-	if (opcode == OP_CALL || opcode == OP_ENTRY)
+	switch (dom->opcode) {
+	case OP_CALL: case OP_ENTRY:
 		return local ? 0 : -1;
-	if (opcode != OP_LOAD && opcode != OP_STORE)
+	case OP_LOAD: case OP_STORE:
+		break;
+	default:
 		return 0;
+	}
+
 	if (dom->src != pseudo) {
 		if (local)
 			return 0;
-- 
2.30.0


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

* [PATCH 2/5] asm-mem: add testcase for missing reload after asm memops
  2021-02-21 22:34 [PATCH 0/5] teach memory simplification about ASM instructions Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 1/5] reorg dominates() Luc Van Oostenryck
@ 2021-02-21 22:34 ` Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 3/5] asm-mem: does it clobber memory? Luc Van Oostenryck
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-02-21 22:34 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Memory simplification is done with the help of the function
dominates() which determine when memory instructions interfere.

This function handles OP_CALLs, OP_LOADs and OP_STOREs but
memory can also be changed via OP_ASMs.

Add a testcase showing this.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/mem2reg/asm-reload0.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 validation/mem2reg/asm-reload0.c

diff --git a/validation/mem2reg/asm-reload0.c b/validation/mem2reg/asm-reload0.c
new file mode 100644
index 000000000000..c9e297dde428
--- /dev/null
+++ b/validation/mem2reg/asm-reload0.c
@@ -0,0 +1,15 @@
+static int asm_reload(void)
+{
+	int mem = 0;
+	asm volatile ("[%1] <= 1" : "=m" (mem));
+	return mem;
+}
+
+/*
+ * check-name: asm-reload0
+ * check-command: test-linearize $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: load\\.
+ */
-- 
2.30.0


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

* [PATCH 3/5] asm-mem: does it clobber memory?
  2021-02-21 22:34 [PATCH 0/5] teach memory simplification about ASM instructions Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 1/5] reorg dominates() Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 2/5] asm-mem: add testcase for missing reload after asm memops Luc Van Oostenryck
@ 2021-02-21 22:34 ` Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 4/5] asm-mem: does it output to memory? Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 5/5] asm-mem: teach dominates() about OP_ASM Luc Van Oostenryck
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-02-21 22:34 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

An asm statement can specify that it clobbers memory.
Add this info directly in the corresponding instruction, avoiding
the need to scan the clobber list each time.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c | 8 +++++++-
 linearize.h | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/linearize.c b/linearize.c
index 33d641b40de6..4140b60caebd 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2174,7 +2174,7 @@ static void add_asm_output(struct entrypoint *ep, struct instruction *insn, stru
 static pseudo_t linearize_asm_statement(struct entrypoint *ep, struct statement *stmt)
 {
 	struct instruction *insn;
-	struct expression *expr;
+	struct expression *expr, *clob;
 	struct asm_rules *rules;
 	struct asm_operand *op;
 
@@ -2206,6 +2206,12 @@ static pseudo_t linearize_asm_statement(struct entrypoint *ep, struct statement
 		add_asm_output(ep, insn, op);
 	} END_FOR_EACH_PTR(op);
 
+	/* and finally, look if it clobbers memory */
+	FOR_EACH_PTR(stmt->asm_clobbers, clob) {
+		if (!strcmp(clob->string->data, "memory"))
+			insn->clobber_memory = 1;
+	} END_FOR_EACH_PTR(clob);
+
 	return VOID;
 }
 
diff --git a/linearize.h b/linearize.h
index a77e4b3e5f6f..fb51327684bb 100644
--- a/linearize.h
+++ b/linearize.h
@@ -150,6 +150,7 @@ struct instruction {
 		struct /* asm */ {
 			const char *string;
 			struct asm_rules *asm_rules;
+			int clobber_memory:1;
 		};
 	};
 };
-- 
2.30.0


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

* [PATCH 4/5] asm-mem: does it output to memory?
  2021-02-21 22:34 [PATCH 0/5] teach memory simplification about ASM instructions Luc Van Oostenryck
                   ` (2 preceding siblings ...)
  2021-02-21 22:34 ` [PATCH 3/5] asm-mem: does it clobber memory? Luc Van Oostenryck
@ 2021-02-21 22:34 ` Luc Van Oostenryck
  2021-02-21 22:34 ` [PATCH 5/5] asm-mem: teach dominates() about OP_ASM Luc Van Oostenryck
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-02-21 22:34 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

If an asm statement have a memory output operand, it modifies memory.

Since this information is needed during memops simplification,
add this info directly in the corresponding instruction,
avoiding the need to scan the output operands list each time.

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

diff --git a/linearize.c b/linearize.c
index 4140b60caebd..0c9b0e59cc4b 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2153,6 +2153,7 @@ static void add_asm_output_address(struct entrypoint *ep, struct instruction *in
 
 	pseudo = linearize_expression(ep, op->expr);
 	add_asm_rule(insn, &insn->asm_rules->outputs, op, pseudo);
+	insn->output_memory = 1;
 }
 
 static void add_asm_output(struct entrypoint *ep, struct instruction *insn, struct asm_operand *op)
diff --git a/linearize.h b/linearize.h
index fb51327684bb..cf0cf066a8e5 100644
--- a/linearize.h
+++ b/linearize.h
@@ -151,6 +151,7 @@ struct instruction {
 			const char *string;
 			struct asm_rules *asm_rules;
 			int clobber_memory:1;
+			int output_memory:1;
 		};
 	};
 };
-- 
2.30.0


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

* [PATCH 5/5] asm-mem: teach dominates() about OP_ASM
  2021-02-21 22:34 [PATCH 0/5] teach memory simplification about ASM instructions Luc Van Oostenryck
                   ` (3 preceding siblings ...)
  2021-02-21 22:34 ` [PATCH 4/5] asm-mem: does it output to memory? Luc Van Oostenryck
@ 2021-02-21 22:34 ` Luc Van Oostenryck
  4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2021-02-21 22:34 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

The function dominates() needs to know if an OP_ASM instruction
may modify.

Use the information now available in the instruction to return
the answer.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 flow.c                           | 6 ++++++
 validation/mem2reg/asm-reload0.c | 1 -
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/flow.c b/flow.c
index 5751ce756518..5d63018798d6 100644
--- a/flow.c
+++ b/flow.c
@@ -495,6 +495,12 @@ int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom
 		return local ? 0 : -1;
 	case OP_LOAD: case OP_STORE:
 		break;
+	case OP_ASM:
+		if (dom->clobber_memory)
+			return -1;
+		if (dom->output_memory)
+			return -1;
+		return 0;
 	default:
 		return 0;
 	}
diff --git a/validation/mem2reg/asm-reload0.c b/validation/mem2reg/asm-reload0.c
index c9e297dde428..ce1829e02724 100644
--- a/validation/mem2reg/asm-reload0.c
+++ b/validation/mem2reg/asm-reload0.c
@@ -8,7 +8,6 @@ static int asm_reload(void)
 /*
  * check-name: asm-reload0
  * check-command: test-linearize $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-contains: load\\.
-- 
2.30.0


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

end of thread, other threads:[~2021-02-21 22:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-21 22:34 [PATCH 0/5] teach memory simplification about ASM instructions Luc Van Oostenryck
2021-02-21 22:34 ` [PATCH 1/5] reorg dominates() Luc Van Oostenryck
2021-02-21 22:34 ` [PATCH 2/5] asm-mem: add testcase for missing reload after asm memops Luc Van Oostenryck
2021-02-21 22:34 ` [PATCH 3/5] asm-mem: does it clobber memory? Luc Van Oostenryck
2021-02-21 22:34 ` [PATCH 4/5] asm-mem: does it output to memory? Luc Van Oostenryck
2021-02-21 22:34 ` [PATCH 5/5] asm-mem: teach dominates() about OP_ASM Luc Van Oostenryck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.