Re: [PATCH 4/6] simplify ((x & M) >> S) when (M >> S) == (-1 >> S)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 19/08/18 10:29, Luc Van Oostenryck wrote:
> The instructions LSR(AND(x, M), S) are already simplified into
> AND(LSR(x, S), (M >> 12)) but only if AND(x, M) has a single user.

s/(M >> 12)/(M >> S)/

ATB,
Ramsay Jones

> 
> 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@xxxxxxxxx>
> ---
>  simplify.c                  | 2 ++
>  validation/optim/lsr-and1.c | 1 -
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/simplify.c b/simplify.c
> index fe264417e..8ace8a5da 100644
> --- a/simplify.c
> +++ b/simplify.c
> @@ -654,6 +654,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 906d9946f..ad249848b 100644
> --- a/validation/optim/lsr-and1.c
> +++ b/validation/optim/lsr-and1.c
> @@ -11,7 +11,6 @@ unsigned foo(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$
> 



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux