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

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

 




On 16/08/18 23:12, Luc Van Oostenryck wrote:
> In an expression like this, if the inner constant (K) and
> the mask are disjoint ((K & M) == 0), then the OR with
> the constant is unneeded and can be optimized away since
> the constant will be 'cleared' by the mask, giving: OP(x, K)
> 
> For example, code like:
> 	int foo(int x)
> 	{
> 		return (x | 0xfffff000) & 0xfff;
> 	}

Sorry to be dense, but I'm lost again. The above example implies
to me that OP == &, C == 0xfffff000, K == 0xfff. So what is M?
Yes ((K & C) == 0) leaving OP(x, K) => (x & 0xfff).

Again where is M coming from?

> 
> is now optimized into:
> 	foo:
> 		and.32      %r3 <- %arg1, $0xfff
> 		ret.32      %r3
> 
> while previously the OR mask was not optimized away:
> 	foo:
> 		or.32       %r2 <- %arg1, $0xfffff000
> 		and.32      %r3 <- %r2, $0xfff
> 		ret.32      %r3
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> ---
>  simplify.c                          | 9 +++++++++
>  validation/optim/and-or-bf0.c       | 1 -
>  validation/optim/and-or-constant0.c | 1 -
>  3 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/simplify.c b/simplify.c
> index e985a1db7..edc84e3ba 100644
> --- a/simplify.c
> +++ b/simplify.c
> @@ -609,6 +609,15 @@ static int simplify_mask_or(struct instruction *insn, unsigned long long mask, s
>  	if (src2->type == PSEUDO_REG) {
>  		if ((rc = simplify_mask_or_and(insn, mask, src2, src1)))
>  			return rc;
> +	} else if (src2->type == PSEUDO_VAL) {
> +		unsigned long long oval = src2->value;
> +		unsigned long long nval = oval & mask;
> +		// Try to simplify:
> +		//	OP(OR(x, C), K)
> +		if (nval == 0) {
> +			// if (C & M) == 0: OR(x, C) -> x

Again (C & M) ?

confused again! ;-)

ATB,
Ramsay Jones

> +			return replace_pseudo(insn, &insn->src1, src1);
> +		}
>  	}
>  	return 0;
>  }
> diff --git a/validation/optim/and-or-bf0.c b/validation/optim/and-or-bf0.c
> index a17ff82d3..cfaff4f20 100644
> --- a/validation/optim/and-or-bf0.c
> +++ b/validation/optim/and-or-bf0.c
> @@ -17,7 +17,6 @@ void bar(struct s *p, int a)
>  /*
>   * check-name: and-or-bf0
>   * check-command: test-linearize -Wno-decl $file
> - * check-known-to-fail
>   *
>   * check-output-ignore
>   * check-output-pattern(3): and\\.
> diff --git a/validation/optim/and-or-constant0.c b/validation/optim/and-or-constant0.c
> index e3ff0fa46..dcf440f33 100644
> --- a/validation/optim/and-or-constant0.c
> +++ b/validation/optim/and-or-constant0.c
> @@ -6,7 +6,6 @@ int foo(int x)
>  /*
>   * check-name: and-or-constant0
>   * check-command: test-linearize -Wno-decl $file
> - * check-known-to-fail
>   *
>   * check-output-ignore
>   * check-output-excludes: or\\.
> 



[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