Bug 8013 - writing all bitfields in a word
Summary: writing all bitfields in a word
Status: RESOLVED DUPLICATE of bug 336
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.2
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2002-09-23 15:36 UTC by jreiser
Modified: 2003-12-26 02:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-11-08 23:31:54


Attachments
bitfield.i (160 bytes, text/plain)
2003-05-21 15:17 UTC, jreiser
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jreiser 2002-09-23 15:36:00 UTC
There is an opportunity for improved optimization when writing all the bitfields in a word ('int', 'unsigned', or 'long'): construct the entire word result in a register, then perform only one store to memory, instead of writing the fields to memory separately in turn.

The attached bitfield.i generates (with "-O" optimization)
        movl    (%ebx), %ecx
        andl    $16777215, %ecx
        movl    (%edx), %eax
        andl    $-16777216, %eax
        orl     %ecx, %eax
        movl    %eax, (%edx)
        movzbl  3(%ebx), %ecx
        andb    $127, %cl
        movzbl  3(%edx), %eax
        andb    $-128, %al
        orb     %cl, %al
        orb     $-128, %al
        movb    %al, 3(%edx)
which could be improved to
        movl    (%ebx), %eax
        orl     $1<<31, %eax
        movl    %eax, (%edx)
which is much shorter and faster.

Release:
gcc version 3.2

Environment:
Reading specs from /usr/local/gcc-3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
Configured with: ../gcc-3.2/configure --prefix=/usr/local/gcc-3.2
Thread model: posix
gcc version 3.2

How-To-Repeat:
gcc -v -save-temps -O -S bitfield.c
Comment 1 Andrew Pinski 2003-05-24 19:46:45 UTC
confirmed that it still happends on mainline (20030524).
Comment 2 Andrew Pinski 2003-12-26 02:22:17 UTC
This is a dup of bug 336.

*** This bug has been marked as a duplicate of 336 ***