diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-08 01:04:26 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-22 09:25:34 +0200 |
| commit | 9feb4b16da637978ce4abdfe23bf9779521a8b77 (patch) | |
| tree | f577fffd0bb7f2253eb5645e45a210bd4e053060 | |
| parent | 03e845221e1d4e7e43f43a91a1d5b3ee96e58c5c (diff) | |
| download | sparse-dev-9feb4b16da637978ce4abdfe23bf9779521a8b77.tar.gz | |
simplify SHL((x & M') | y, S)
The same simplifications done for LSR can be done for SHL
(with the appropriate mask).
For example, code like:
int foo(int a, int b)
{
return ((a & 0xfff00000) | b) << 12;
}
is now optimized into:
foo:
shl.32 %r5 <- %arg2, $12
ret.32 %r5
while previously it was:
foo:
and.32 %r2 <- %arg1, $0xfff00000
or.32 %r4 <- %r2, %arg2
shl.32 %r5 <- %r4, $12
ret.32 %r5
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 4 | ||||
| -rw-r--r-- | validation/optim/and-or-shl0.c | 1 | ||||
| -rw-r--r-- | validation/optim/and-or-shl1.c | 1 | ||||
| -rw-r--r-- | validation/optim/and-or-shl2.c | 1 | ||||
| -rw-r--r-- | validation/optim/and-or-shlx.c | 1 | ||||
| -rw-r--r-- | validation/optim/sh-or-and0.c | 1 | ||||
| -rw-r--r-- | validation/optim/sh-or-and1.c | 1 | ||||
| -rw-r--r-- | validation/optim/sh-or-and2.c | 1 |
8 files changed, 4 insertions, 7 deletions
@@ -631,6 +631,7 @@ static int simplify_mask_or_and(struct instruction *insn, unsigned long long mas // For the @mask (M): // * if OP(x, K) == AND(x, M), @mask M is K // * if OP(x, K) == LSR(x, S), @mask M is (-1 << S) +// * if OP(x, K) == SHL(x, S), @mask M is (-1 >> S) static int simplify_mask_or(struct instruction *insn, unsigned long long mask, struct instruction *or) { pseudo_t src1 = or->src1; @@ -788,6 +789,9 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v break; mask = bits_mask(insn->size - value) << value; goto replace_mask; + case OP_OR: + mask = bits_mask(size - value); + return simplify_mask_or(insn, mask, def); case OP_SHL: case_shift_shift: // also for LSR - LSR if (def == insn) // cyclic DAG! diff --git a/validation/optim/and-or-shl0.c b/validation/optim/and-or-shl0.c index c9914f22..4850b326 100644 --- a/validation/optim/and-or-shl0.c +++ b/validation/optim/and-or-shl0.c @@ -6,7 +6,6 @@ int foo(int a, int b) /* * check-name: and-or-shl0 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: or\\. diff --git a/validation/optim/and-or-shl1.c b/validation/optim/and-or-shl1.c index 1c7b104c..bea22245 100644 --- a/validation/optim/and-or-shl1.c +++ b/validation/optim/and-or-shl1.c @@ -6,7 +6,6 @@ int foo(int a, int b) /* * check-name: and-or-shl1 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(0): and\\. diff --git a/validation/optim/and-or-shl2.c b/validation/optim/and-or-shl2.c index a0099325..f5f62758 100644 --- a/validation/optim/and-or-shl2.c +++ b/validation/optim/and-or-shl2.c @@ -6,7 +6,6 @@ int foo(int x, int y) /* * check-name: and-or-shl2 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: and\\..*\\$0xfff0f diff --git a/validation/optim/and-or-shlx.c b/validation/optim/and-or-shlx.c index b6862800..ec2a2ced 100644 --- a/validation/optim/and-or-shlx.c +++ b/validation/optim/and-or-shlx.c @@ -6,7 +6,6 @@ unsigned int foo(unsigned int x, unsigned int y, unsigned int a) /* * check-name: and-or-shlx * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(1): and\\. diff --git a/validation/optim/sh-or-and0.c b/validation/optim/sh-or-and0.c index 4a099df2..02f0cb03 100644 --- a/validation/optim/sh-or-and0.c +++ b/validation/optim/sh-or-and0.c @@ -11,7 +11,6 @@ unsigned shl_or_and0(unsigned x, unsigned b) /* * check-name: sh-or-and0 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(1): lsr\\. diff --git a/validation/optim/sh-or-and1.c b/validation/optim/sh-or-and1.c index 44a07ec5..7b79bbf3 100644 --- a/validation/optim/sh-or-and1.c +++ b/validation/optim/sh-or-and1.c @@ -11,7 +11,6 @@ unsigned shl_or_and1(unsigned x, unsigned b) /* * check-name: sh-or-and1 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(1): lsr\\. diff --git a/validation/optim/sh-or-and2.c b/validation/optim/sh-or-and2.c index c292057c..241aeaff 100644 --- a/validation/optim/sh-or-and2.c +++ b/validation/optim/sh-or-and2.c @@ -11,7 +11,6 @@ unsigned shl_or_and2(unsigned x, unsigned b) /* * check-name: sh-or-and2 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(1): lsr\\. |
