https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86106

            Bug ID: 86106
           Summary: powerpc: Suboptimal logical operation
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophe.le...@c-s.fr
  Target Milestone: ---

unsigned int g(unsigned int val)
{
        unsigned int mask = 0x7f7f7f7f;

        return ~(((val & mask) + mask) | val | mask);
}

generates the following:

00000020 <g>:
  20:   3d 20 7f 7f     lis     r9,32639
  24:   61 29 7f 7f     ori     r9,r9,32639
  28:   7c 69 48 38     and     r9,r3,r9
  2c:   3d 29 7f 7f     addis   r9,r9,32639
  30:   39 29 7f 7f     addi    r9,r9,32639
  34:   7d 23 1b 78     or      r3,r9,r3
  38:   64 63 7f 7f     oris    r3,r3,32639
  3c:   60 63 7f 7f     ori     r3,r3,32639
  40:   7c 63 18 f8     not     r3,r3
  44:   4e 80 00 20     blr

Whereas I'd expect something like:

        lis     r4,32639
        ori     r4,r4,32639
        and     r9,r3,r4
        or      r3,r3,r4
        add     r9,r9,r4
        nor     r3,r9,r3
        blr

Reply via email to