This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/18038] New: addition in a multibit bitfield is inefficient
- From: "kazu at cs dot umass dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Oct 2004 05:06:52 -0000
- Subject: [Bug middle-end/18038] New: addition in a multibit bitfield is inefficient
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Consider:
struct B {
unsigned b : 2;
};
void
store (struct B *b, int v)
{
b->b += v;
}
./cc1 -O2 -fomit-frame-pointer -mregparm=3 generates
store:
movb (%eax), %cl
andl $3, %ecx
addl %edx, %ecx
andl $3, %ecx
movl (%eax), %edx
andl $-4, %edx
orl %ecx, %edx
movl %edx, (%eax)
ret
We don't need two "andl". We could do something like
store:
movl (%eax), %ecx
addl %ecx, %edx
andl $3, %edx
andl $-4, %ecx
orl %ecx, %edx
movl %edx, (%eax)
ret
--
Summary: addition in a multibit bitfield is inefficient
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=18038