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

[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 equal to the outer mask (M),
> then the OR operation is unneeded and can be replaced by M itself,
> giving: OP(M', K) with M' == (C & M)
> 
> For example, code like:
> 	unsigned int foo(int x)
> 	{
> 		return (x | 7) & 2;
> 	}

C == 7, K == 2, OP == &, (C & K) == K. Hmm, so M == K?

ATB,
Ramsay Jones

> 
> is now simplified into:
> 	foo:
> 		ret.32      $2
> 
> which previously was not optimized
> 	foo:
> 		or.32       %r2 <- %arg1, $7
> 		and.32      %r3 <- %r2, $2
> 		ret.32      %r3
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> ---
>  simplify.c                          | 4 ++++
>  validation/optim/and-or-constant1.c | 1 -
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/simplify.c b/simplify.c
> index edc84e3ba..755371002 100644
> --- a/simplify.c
> +++ b/simplify.c
> @@ -618,6 +618,10 @@ static int simplify_mask_or(struct instruction *insn, unsigned long long mask, s
>  			// if (C & M) == 0: OR(x, C) -> x
>  			return replace_pseudo(insn, &insn->src1, src1);
>  		}
> +		if (nval == mask) {
> +			// if (C & M) == M: OR(x, C) -> (C & M)
> +			return replace_pseudo(insn, &insn->src1, value_pseudo(nval));
> +		}
>  	}
>  	return 0;
>  }
> diff --git a/validation/optim/and-or-constant1.c b/validation/optim/and-or-constant1.c
> index 3f1c90528..49823d5ca 100644
> --- a/validation/optim/and-or-constant1.c
> +++ b/validation/optim/and-or-constant1.c
> @@ -6,7 +6,6 @@ int foo(int x)
>  /*
>   * check-name: or-and-constant1
>   * check-command: test-linearize -Wno-decl $file
> - * check-known-to-fail
>   *
>   * check-output-ignore
>   * check-output-contains: ret\\..*\\$0xfff
> 



[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