On 11/22/20 6:35 PM, Eugene Rozenfeld via Gcc-patches wrote:
> Simplify
> ((b | c) & a) | b
> to 
> (a & c) | b.
>
> This fixes PR96679.
>
> Tested on x86_64-pc-linux-gnu.
>
> int f(int a, int b, int c)
> {
>     return ((b | c) & a) | b;
> }
>
> Code without the patch:
> or     edx,esi
> and    edx,edi
> mov    eax,edx
> or     eax,esi
> ret
>
> Code with the patch:
> and    edi,edx
> mov    eax,edi
> or     eax,esi
> ret
>
> Eugene
>
> 0001-Optimize-or-and-or-pattern-to-and-or.patch
>
> From 326f186e084c1788c428d581aa3c1a20344ed5b4 Mon Sep 17 00:00:00 2001
> From: Eugene Rozenfeld <ero...@microsoft.com>
> Date: Fri, 20 Nov 2020 18:05:15 -0800
> Subject: [PATCH] Optimize or+and+or pattern to and+or
>
> Simplify ((b | c) & a) | b to (a & c) | b.
> This fixes PR96679.
>
> gcc/
> * match.pd : New patterns.
Thanks.  I've expanded the ChangeLog a bit and pushed this to the trunk.

For future patches, please also include testcases.  While they aren't a
strict requirement, we've found them incredibly useful, even for minor
changes like this.

Jeff
> ---
>  gcc/match.pd | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index cbb4bf0b32d..00294665c98 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1433,6 +1433,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>    (bitop:c (rbitop:c (bit_not @0) @1) @0)
>    (bitop @0 @1)))
>  
> +/* ((x | y) & z) | x -> (z & y) | x */
> +(simplify
> +  (bit_ior:c (bit_and:cs (bit_ior:cs @0 @1) @2) @0)
> +  (bit_ior (bit_and @2 @1) @0))
> +
>  /* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
>  (simplify
>    (bit_and (bit_ior @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)

Reply via email to