diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-18 18:43:38 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-22 09:26:18 +0200 |
| commit | 729be196bb860270de32ec076873c6d327f592a0 (patch) | |
| tree | 9dca57c34c6a1a934a986726d347e16a0b46e55d | |
| parent | c68bfab0e487452d17534393efaa0c8da165aff0 (diff) | |
| download | sparse-dev-729be196bb860270de32ec076873c6d327f592a0.tar.gz | |
simplify ((x & M) >> S) when (M >> S) == (-1 >> S)
The instructions LSR(AND(x, M), S) are already simplified into
AND(LSR(x, S), (M >> S)) but only if AND(x, M) has a single user.
However, if (M >> S) == (-1 >> S), the AND part is redundant and the
whole can always directly be simplified into LSR(x, S).
For example, code like:
unsigned foo(unsigned x)
{
unsigned t = (x & 0xfffff000);
return ((t >> 12) ^ (x >> 12)) & t;
}
is now optimized into:
foo:
ret.32 $0
because (t >> 12) is simplified into (x >> 12).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 2 | ||||
| -rw-r--r-- | validation/optim/lsr-and1.c | 1 |
2 files changed, 2 insertions, 1 deletions
@@ -685,6 +685,8 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v nmask = omask & mask; if (nmask == 0) return replace_with_pseudo(insn, value_pseudo(0)); + if (nmask == mask) + return replace_pseudo(insn, &insn->src1, def->src1); if (nbr_users(pseudo) > 1) break; def->opcode = OP_LSR; diff --git a/validation/optim/lsr-and1.c b/validation/optim/lsr-and1.c index e2eb5059..393679e3 100644 --- a/validation/optim/lsr-and1.c +++ b/validation/optim/lsr-and1.c @@ -12,7 +12,6 @@ unsigned lsr_and1(unsigned x) /* * check-name: lsr-and1 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: ret\\..*\\$0$ |
