[LLVMbugs] [Bug 2035] New: Suboptimal code storing to a bitfield

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Thu Feb 14 06:39:59 PST 2008


           Summary: Suboptimal code storing to a bitfield
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sharparrow1 at yahoo.com
                CC: llvmbugs at cs.uiuc.edu

Take the following code:

void x(struct {int a : 5, b : 5;} *c, int x) {c->a = x;}

llvm-gcc generates the following code sequence:

        movl    4(%esp), %eax
        movw    $65504, %cx
        andw    (%eax), %cx
        movw    $31, %dx
        andw    8(%esp), %dx
        orw     %dx, %cx
        movw    %cx, (%eax)

gcc generates a similar sequence.  However, there is a straightforward sequence
that is two instructions shorter:

movl    4(%esp), %eax
movw    8(%esp), %dx
xorw    (%eax), %dx
andw    $31, %dx
xorw    %dx, (%eax)

This doesn't actually save any logical operations, but it doesn't move stuff
around as much.

I'm not sure if this bug affects real code, since I just came up with it by
experimenting, but it doesn't seem like an unusual sort of construct.  I'm also
not sure if it's actually worth using; it's quite possible I'm missing
something.  That said, it seems like something interesting to investigate.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list