Consider:

struct B {
  unsigned bit : 1;
};

void
plus (struct B *b)
{
  b->bit = b->bit + 1;
}

void
xor (struct B *b)
{
  b->bit = b->bit ^ 1;
}

./cc1 -O2 -fomit-frame-pointer -mregparm=3 generates

plus:
        xorb    $1, (%eax)
        ret

xor:
        movb    (%eax), %cl
        andl    $1, %ecx
        xorl    $1, %ecx
        movzbl  %cl, %ecx
        movl    (%eax), %edx
        andl    $-2, %edx
        orl     %ecx, %edx
        movl    %edx, (%eax)
        ret

Note that the two functions do the same thing.  Obviously, we should optimize
xor just like plus.

-- 
           Summary: a twiddleing of a
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18029

Reply via email to