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@xxxxxxxxx> --- simplify.c | 4 ++++ validation/optim/and-or-shl0.c | 1 - validation/optim/and-or-shl1.c | 1 - validation/optim/and-or-shl2.c | 1 - validation/optim/and-or-shlx.c | 1 - validation/optim/sh-or-and0.c | 1 - validation/optim/sh-or-and1.c | 1 - validation/optim/sh-or-and2.c | 1 - 8 files changed, 4 insertions(+), 7 deletions(-) diff --git a/simplify.c b/simplify.c index fce99551a..ed1db4858 100644 --- a/simplify.c +++ b/simplify.c @@ -600,6 +600,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; @@ -757,6 +758,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 c9914f22c..4850b3262 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 1c7b104cf..bea222450 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 a00993255..f5f62758d 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 b68628006..ec2a2ced4 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 4a099df2d..02f0cb035 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 44a07ec51..7b79bbf32 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 c292057c4..241aeaff2 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\\. -- 2.18.0