Hi

This patch add support for the missing transformation of (x | y) == x -> (y & ~x) == 0. The transformation for (x & y) == x case already exists in simplify-rtx.c since 2014 as of r218503 and this patch only adds a couple of extra patterns for the IOR case.

Citing the example given in PR82439 :

Simple testcase (f1 should generate the same as f2):

int f1(int x, int y) { return (x | y) == x; }
int f2(int x, int y) { return (y & ~x) == 0; }

f1:
        orr     w1, w0, w1
        cmp     w1, w0
        cset    w0, eq
        ret
f2:
        bics    wzr, w1, w0
        cset    w0, eq
        ret

This benefits targets that have the BICS instruction to generate better code. Wilco helped me in showing that even in targets that do not have the BICS instruction, this is no worse and gives out 2 instructions.
For example in x86:

0000000000000000 <f1>:
   0:   09 fe                   or     %edi,%esi
   2:   31 c0                   xor    %eax,%eax
   4:   39 fe                   cmp    %edi,%esi
   6:   0f 94 c0                sete   %al
   9:   c3                      retq

0000000000000010 <f2>:
  10:   f7 d7                   not    %edi
  12:   31 c0                   xor    %eax,%eax
  14:   85 f7                   test   %esi,%edi
  16:   0f 94 c0                sete   %al
  19:   c3                      retq

Testing done: Checked for regressions on bootstrapped aarch64-none-linux-gnu and arm-none-linux-gnueabihf and added new test cases.
Is this ok for trunk?

Sudi

ChangeLog Entries:

*** gcc/ChangeLog ***

2017-01-03  Sudakshina Das  <sudi....@arm.com>

        PR target/82439
        * simplify-rtx.c (simplify_relational_operation_1): Add
        simplifications of (x|y) == x for BICS pattern.

*** gcc/testsuite/ChangeLog ***

2017-01-03  Sudakshina Das  <sudi....@arm.com>

        PR target/82439
        * gcc.target/aarch64/bics_5.c: New test.
        * gcc.target/arm/bics_5.c: Likewise.

Reply via email to