[Bug target/58741] New: x86: Better optimization for operations on global long long and long variables

asmtwiddler at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Oct 15 21:34:00 GMT 2013


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

            Bug ID: 58741
           Summary: x86: Better optimization for operations on global long
                    long and long variables
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: asmtwiddler at gmail dot com

Hello all,

I am using the experimental branch as well as version 4.6.3 to compile the
following code using "gcc -S -O2 -Wall"

The code below produces inefficient assembly for x86 (i686-linux-gnu):
unsigned long long val;
unsigned long small;
unsigned long long example() {
    return val | small;
}

Which gives the following assembly:
example:
    movl    small, %ecx
    movl    val, %eax
    movl    val+4, %edx
    pushl    %ebx
    xorl    %ebx, %ebx
    orl    %ecx, %eax
    orl    %ebx, %edx
    popl    %ebx
    ret

A more efficient implementation could be (which is generated if "extern const"
is added to the val and small definitions):
example:
    movl    small, %eax
    movl    val+4, %edx
    orl    val, %eax
    ret

This inefficiency also occurs if the bitwise-or is replaced with an bitwise-xor
or subtraction.

Thanks



More information about the Gcc-bugs mailing list