public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/18029] New: a twiddleing of a
@ 2004-10-16  2:57 kazu at cs dot umass dot edu
  2004-10-16  2:57 ` [Bug middle-end/18029] an xor of a single bit bitfield is inefficient kazu at cs dot umass dot edu
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-10-16  2:57 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-03-02 16:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-16  2:57 [Bug middle-end/18029] New: a twiddleing of a kazu at cs dot umass dot edu
2004-10-16  2:57 ` [Bug middle-end/18029] an xor of a single bit bitfield is inefficient kazu at cs dot umass dot edu
2004-10-16  3:05 ` pinskia at gcc dot gnu dot org
2004-10-16 15:49 ` kazu at cs dot umass dot edu
2004-10-17 11:26 ` giovannibajo at libero dot it
2005-01-13 18:57 ` pinskia at gcc dot gnu dot org
2005-03-02 16:06 ` cvs-commit at gcc dot gnu dot org
2005-03-02 16:08 ` kazu at cs dot umass dot edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).