Optimize a ^ ((a ^ b) & mask) to (~mask & a) | (b & mask).
authorHaochen Jiang <haochen.jiang@intel.com>
Wed, 12 Jan 2022 02:01:21 +0000 (10:01 +0800)
committerliuhongt <hongtao.liu@intel.com>
Thu, 13 Jan 2022 05:03:11 +0000 (13:03 +0800)
commit5f19303ada7db92c155332e7ba317233ca05946b
tree8f2866087cd1d5b3409b0c79de2ccf5206a50ef8
parent080a06fcb076b3586ee4b00d415ae177f0b76b18
Optimize a ^ ((a ^ b) & mask) to (~mask & a) | (b & mask).

From the perspective of the pipeline, `andn + and + ior` version take
2 cycles(AND and ANDN doesn't have dependence), but xor + and + xor
will take 3 cycles.

-       xorl    %edi, %esi
        andl    %edx, %esi
-       movl    %esi, %eax
-       xorl    %edi, %eax
+       andn    %edi, %edx, %eax
+       orl     %esi, %eax

gcc/ChangeLog:

PR target/94790
* config/i386/i386.md (*xor2andn): New define_insn_and_split.

gcc/testsuite/ChangeLog:

PR target/94790
* gcc.target/i386/pr94790-1.c: New test.
* gcc.target/i386/pr94790-2.c: Ditto.
gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/pr94790-1.c [new file with mode: 0755]
gcc/testsuite/gcc.target/i386/pr94790-2.c [new file with mode: 0755]