Consider:

struct B {
  unsigned bit : 2;
};

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

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

plus:
        movb    (%eax), %cl
        andl    $3, %ecx
        orl     $1, %ecx
        andl    $3, %ecx
        movl    (%eax), %edx
        andl    $-4, %edx
        orl     %ecx, %edx
        movl    %edx, (%eax)
        ret

Note that we could just do "orl $1, (%eax)"

-- 
           Summary: OR is inefficient in 2-bit bitfield
           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=18030

Reply via email to