public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/42172]  New: inefficient bit fields assignments
@ 2009-11-25  9:16 carrot at google dot com
  2010-08-09 15:04 ` [Bug tree-optimization/42172] " bernds at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: carrot at google dot com @ 2009-11-25  9:16 UTC (permalink / raw)
  To: gcc-bugs

The attached test case contains several continuous bit fields assignment,
compile it with options -mthumb -Os, gcc generates

        .fnstart
.LFB1:
        ldrb    r3, [r0]
        mov     r2, #7
        bic     r3, r3, r2
        strb    r3, [r0]
        ldrb    r3, [r0]
        mov     r2, #56
        bic     r3, r3, r2
        mov     r2, #8
        orr     r3, r3, r2
        strb    r3, [r0]
        ldrb    r3, [r0]
        mov     r2, #64
        bic     r3, r3, r2
        strb    r3, [r0]
        ldrb    r2, [r0]
        mov     r3, #127
        and     r3, r3, r2
        strb    r3, [r0]
        @ sp needed for prologue
        bx      lr

The 4 fields are contained in one word, for each field assignment the code
loads the word, changes the field, then write the word back. A better code
sequence should load the word once, change all 4 fields, then write back the
changed word.

        ldrb    r3, [r0]
        mov     r2, #255             // bit mask
        bic     r3, r3, r2
        mov     r2, #8               // the new value of all 4 fields
        orr     r3, r3, r2
        strb    r3, [r0]
        @ sp needed for prologue
        bx      lr

or more aggressively if the word contains only these four fields

        mov     r3, #8
        strb    r3, [r0]
        @ sp needed for prologue
        bx      lr


-- 
           Summary: inefficient bit fields assignments
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carrot at google dot com
 GCC build triplet: i686-linux
  GCC host triplet: i686-linux
GCC target triplet: arm-eabi


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


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

end of thread, other threads:[~2021-07-21  3:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-42172-4@http.gcc.gnu.org/bugzilla/>
2011-03-25 20:07 ` [Bug tree-optimization/42172] inefficient bit fields assignments jakub at gcc dot gnu.org
2011-04-28 16:52 ` rguenth at gcc dot gnu.org
2013-01-17  0:26 ` janis at gcc dot gnu.org
2015-04-09  3:47 ` amker at gcc dot gnu.org
2015-04-09 13:57 ` segher at gcc dot gnu.org
2021-07-21  3:11 ` pinskia at gcc dot gnu.org
2021-07-21  3:18 ` pinskia at gcc dot gnu.org
2009-11-25  9:16 [Bug target/42172] New: " carrot at google dot com
2010-08-09 15:04 ` [Bug tree-optimization/42172] " bernds at gcc dot gnu dot org
2010-08-19 17:32 ` bernds at gcc dot gnu dot org
2010-09-01  9:07 ` ramana at gcc dot gnu dot org
2010-09-01  9:07 ` ramana 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).