From 98307d4dea6d5a1d30f1e042b86ef9e573468999 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 1 Dec 2004 09:05:50 -0700 Subject: [PATCH] When simplifying memops, follow the whole chain of adds/subs. This means we find multiple cases faster, but more importantly, it also means that if the chain is infinite, we can trivially notice. We used to just notice immediate recursive uses, not the more complex cases. --- simplify.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/simplify.c b/simplify.c index 2244b0d0..853b57ed 100644 --- a/simplify.c +++ b/simplify.c @@ -404,7 +404,7 @@ static int simplify_unop(struct instruction *insn) return 0; } -static int simplify_memop(struct instruction *insn) +static int simplify_one_memop(struct instruction *insn, pseudo_t orig) { pseudo_t addr = insn->src; pseudo_t new, off; @@ -432,7 +432,7 @@ static int simplify_memop(struct instruction *insn) offset: /* Invalid code */ - if (new == addr) { + if (new == orig) { if (new == VOID) return 0; new = VOID; @@ -444,6 +444,22 @@ offset: return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP; } +/* + * We walk the whole chain of adds/subs backwards. That's not + * only more efficient, but it allows us to find looops. + */ +static int simplify_memop(struct instruction *insn) +{ + int one, ret = 0; + pseudo_t orig = insn->src; + + do { + one = simplify_one_memop(insn, orig); + ret |= one; + } while (one); + return ret; +} + static int simplify_cast(struct instruction *insn) { int orig_size; -- 2.11.4.GIT