public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/18041] New: OR of two single-bit bitfields is inefficient
@ 2004-10-17 16:36 kazu at cs dot umass dot edu
2004-10-17 17:01 ` [Bug middle-end/18041] " pinskia at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-10-17 16:36 UTC (permalink / raw)
To: gcc-bugs
Consider:
struct B {
unsigned bit0 : 1;
unsigned bit1 : 1;
};
void
foo (struct B *b)
{
b->bit0 = b->bit0 | b->bit1;
}
./cc1 -O2 -fomit-frame-pointer -mregparm=3 generates
foo:
movb (%eax), %dl <- one load
movb %dl, %cl
shrb %cl
orl %edx, %ecx
andl $1, %ecx
movl (%eax), %edx <- another load from the same place
andl $-2, %edx
orl %ecx, %edx <- the second OR
movl %edx, (%eax)
ret
We could do something like
movb (%eax), %cl
movb %cl, %dl
shrb %dl
andl $1, %edx
orl %ecx, %edx
movb %dl, (%eax)
ret
or
movb (%eax), %dl
testb $2, %dl
je .L6
orl $1, %edx
movb %dl, (%eax)
.L6:
ret
expr.c actually has code intended to emit the second suggestion
(look for "Check for |= or &= of a bitfield" in expr.c), but it is
practically disabled because we get tree like this
b->bit0 = (<unnamed type>) (unsigned char)
((signed char) b->bit0 | (signed char) b->bit1)
whereas the code in expr.c expects
b->bit0 = b->bit0 | b->bit1;
The code is not triggered even in gcc-3.3. Probably it is practically
disabled for a long time.
--
Summary: OR of two single-bit bitfields 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=18041
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/18041] OR of two single-bit bitfields is inefficient
2004-10-17 16:36 [Bug middle-end/18041] New: " kazu at cs dot umass dot edu
@ 2004-10-17 17:01 ` pinskia at gcc dot gnu dot org
2004-10-17 17:05 ` pinskia at gcc dot gnu dot org
2005-02-07 19:21 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-17 17:01 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-17 17:01 -------
Hmm, there is only one load on PPC (with either side):
same bit layout as below:
lwz r0,0(r3)
rlwinm r2,r0,0,31,31
rlwinm r9,r0,31,31,31
or r2,r2,r9
rlwimi r0,r2,0,31,31
stw r0,0(r3)
blr
The oposite bit layout:
lwz r0,0(r3)
srwi r2,r0,31
rlwinm r9,r0,2,31,31
or r2,r2,r9
rlwimi r0,r2,31,0,0
stw r0,0(r3)
blr
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18041
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/18041] OR of two single-bit bitfields is inefficient
2004-10-17 16:36 [Bug middle-end/18041] New: " kazu at cs dot umass dot edu
2004-10-17 17:01 ` [Bug middle-end/18041] " pinskia at gcc dot gnu dot org
@ 2004-10-17 17:05 ` pinskia at gcc dot gnu dot org
2005-02-07 19:21 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-17 17:05 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-17 17:05 -------
Confirmed about the extra and (I don't know why the extra load is in x86).
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2004-10-17 17:05:33
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18041
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/18041] OR of two single-bit bitfields is inefficient
2004-10-17 16:36 [Bug middle-end/18041] New: " kazu at cs dot umass dot edu
2004-10-17 17:01 ` [Bug middle-end/18041] " pinskia at gcc dot gnu dot org
2004-10-17 17:05 ` pinskia at gcc dot gnu dot org
@ 2005-02-07 19:21 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-07 19:21 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-02-07 06:02 -------
This is a much harder problem than doing a simplification at combine time because we have five
instructions to worry about.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18041
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-05-11 11:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-18041-4@http.gcc.gnu.org/bugzilla/>
2011-05-06 13:25 ` [Bug middle-end/18041] OR of two single-bit bitfields is inefficient rguenth at gcc dot gnu.org
2011-05-10 11:48 ` rguenth at gcc dot gnu.org
2011-05-11 11:44 ` rguenth at gcc dot gnu.org
2004-10-17 16:36 [Bug middle-end/18041] New: " kazu at cs dot umass dot edu
2004-10-17 17:01 ` [Bug middle-end/18041] " pinskia at gcc dot gnu dot org
2004-10-17 17:05 ` pinskia at gcc dot gnu dot org
2005-02-07 19:21 ` pinskia at gcc dot gnu dot org
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).