Re: [PATCH v2 14/15] simplify OP((x | C), K) when (C & M) != C

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

 




On 16/08/18 23:12, Luc Van Oostenryck wrote:
> If the effective mask (C & M) is different than the outer mask C,
> then this later can be replaced by the smaller (C & M), giving:
> OP((x | M'), K) with M' == (C & M).
> 
> For example, code like:
> 	int foo(int x)
> 	{
> 		return (x | 0xfffffff0) & 0xfff;
> 	}

C = 0xfffffff0, OP = &, K = 0xfff, (C & K) = 0xff0, so
OP((x | M'), K) where M' = (C & K).

ATB,
Ramsay Jones

> 
> is now simplified into:
> 	foo:
> 		or.32       %r2 <- %arg1, $0xff0
> 		and.32      %r3 <- %r2, $0xfff
> 		ret.32      %r3
> 
> while previously, the constant was not reduced:
> 	foo:
> 		or.32       %r2 <- %arg1, $0xfffffff0
> 		and.32      %r3 <- %r2, $0xfff
> 		ret.32      %r3
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> ---
>  simplify.c                          | 4 ++++
>  validation/optim/and-or-constant2.c | 1 -
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/simplify.c b/simplify.c
> index 755371002..5a802d207 100644
> --- a/simplify.c
> +++ b/simplify.c
> @@ -622,6 +622,10 @@ static int simplify_mask_or(struct instruction *insn, unsigned long long mask, s
>  			// if (C & M) == M: OR(x, C) -> (C & M)
>  			return replace_pseudo(insn, &insn->src1, value_pseudo(nval));
>  		}
> +		if (nval != oval && !multi_users(or->target)) {
> +			// if (C & M) != C: OR(x, C) -> OR(x, (C & M))
> +			return replace_pseudo(or, &or->src2, value_pseudo(nval));
> +		}
>  	}
>  	return 0;
>  }
> diff --git a/validation/optim/and-or-constant2.c b/validation/optim/and-or-constant2.c
> index 82e0d3c69..d7e66f9c0 100644
> --- a/validation/optim/and-or-constant2.c
> +++ b/validation/optim/and-or-constant2.c
> @@ -6,7 +6,6 @@ int foo(int x)
>  /*
>   * check-name: and-or-constant2
>   * check-command: test-linearize -Wno-decl $file
> - * check-known-to-fail
>   *
>   * check-output-ignore
>   * check-output-contains: or\\..*\\$0xff0
> 



[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