On Thu, Nov 12, 2020 at 2:53 AM Eugene Rozenfeld via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Simplify (a ^ b) & ((b ^ c) ^ a) --> (a ^ b) & ~c. > > int f(int a, int b, int c) > { > return (a ^ b) & ((b ^ c) ^ a); > } > > Code without the patch: > mov eax,edx > xor eax,esi > xor eax,edi > xor edi,esi > and eax,edi > ret > > Code with the patch: > xor edi,esi > andn eax,edx,edi > ret > > Simplify (a ^ b) | ((b ^ c) ^ a) --> (a ^ b) | c. > int g(int a, int b, int c) > { > return (a ^ b) | ((b ^ c) ^ a); > } > > Code without the patch: > mov eax,edx > xor eax,esi > xor eax,edi > xor edi,esi > or eax,edi > ret > > Code with the patch: > xor edi,esi > mov eax,edi > or eax,edx > ret > > This fixes PR96671.
+/* (a ^ b) & ((b ^ c) ^ a) --> (a ^ b) & ~c */ +(simplify + (bit_and:c (bit_xor:c @0 @1) (bit_xor:cs (bit_xor:c @1 @2) @0)) + (bit_and (bit_xor @0 @1) (bit_not @2))) you should be able to re-use the first bit_xor by doing +/* (a ^ b) & ((b ^ c) ^ a) --> (a ^ b) & ~c */ +(simplify + (bit_and:c (bit_xor:c@3 @0 @1) (bit_xor:cs (bit_xor:c @1 @2) @0)) + (bit_and @3 (bit_not @2))) For completeness the last (bit_xor:c @1 @2) should also have a :s +/* (a ^ b) | ((b ^ c) ^ a) --> (a ^ b) | c */ +(simplify + (bit_ior:c (bit_xor:c @0 @1) (bit_xor:c (bit_xor:c @1 @2) @0)) + (bit_ior (bit_xor @0 @1) @2)) completely misses :s here and the same comment about the re-use of the existing xor applies. Otherwise looks OK to me, sorry for the delay. Thanks, Richard. > Tested on x86_64-pc-linux-gnu. >