[PATCH] [tree-optimization] Optimize two patterns with three xors.

Eugene Rozenfeld Eugene.Rozenfeld@microsoft.com
Thu Nov 12 01:52:42 GMT 2020


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.

Tested on x86_64-pc-linux-gnu.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Optimize-two-patterns-with-three-xors.patch
Type: application/octet-stream
Size: 1127 bytes
Desc: 0001-Optimize-two-patterns-with-three-xors.patch
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20201112/b5c71240/attachment.obj>


More information about the Gcc-patches mailing list