[4/5] symaddr: fold them into loads & stores
diff mbox

Message ID 20180309023010.94475-5-luc.vanoostenryck@gmail.com
State Under Review
Headers show

Commit Message

Luc Van Oostenryck March 9, 2018, 2:30 a.m. UTC
Memory simplification can and effectively do a more precise
job when more information is known about the memop's address.
For example, it knows that two distinct symbol won't alias
while, of course, nothing similar can be said if the address
are mere pointers to some unknown objects.
In other words, we prefer to see:
	load.32         %r2, 0[s]
than:
	symaddr.32	%r1, s
	load.32         %r2, 0[%r1]

So, to insure that memop use the symbol when possible,
for each memop using the result of an OP_SYMADDR as
address, replace the address by the symbol itself.

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

Comments

Luc Van Oostenryck March 9, 2018, 8:27 p.m. UTC | #1
In fact, this one is totally unneeded, the same is already done in
simplify_one_memop().

-- Luc
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/simplify.c b/simplify.c
index a2edda479..b3cd76e3d 100644
--- a/simplify.c
+++ b/simplify.c
@@ -901,6 +901,16 @@  static int simplify_memop(struct instruction *insn)
 	int one, ret = 0;
 	pseudo_t orig = insn->src;
 
+	// try to fold symbol address into the access
+	if (orig->type == PSEUDO_REG) {
+		struct instruction *def = orig->def;
+		if (def->opcode == OP_SYMADDR) {
+			pseudo_t sym = def->symbol;
+			kill_use(&insn->src);
+			use_pseudo(insn, sym, &insn->src);
+		}
+	}
+
 	do {
 		one = simplify_one_memop(insn, orig);
 		ret |= one;