{PING] [PATCH] Sign extension elimination

H. J. Lu hjl@lucon.org
Mon Apr 17 20:07:00 GMT 2006


On Mon, Apr 17, 2006 at 09:31:54AM +0300, Leehod Baruch wrote:
> > I don't think the current SEE worked well for x86-64. We have been
> > trying to extend it to x86-64. My main concern is when SEE is enabled,
> > some very odd x86-64 code is generated for some simple testcases.
> Can you point out, what are the testcases and what is the odd code that
> was generated.
> 

For

short logadd (short *a, short *b)
{
  return *a + *b;
}

The old "-O3 -g" generates:

logadd:
        addl    %edi, %esi
        movswl  %si,%eax
        ret

With SEE, I got

logadd:
        leal    (%rsi,%rdi), %eax
        cwtl
        ret

I am not sure if the new one is better. The main problem for x86-64 is
SEE is just moving instructions around or replacing one with another.
For the testcase in

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

"-O2 -fsee" doesn't reduce number of total instructions at all. It
replaces

.L2:
        mov     %edx, %eax
        movl    state+4(%rcx), %edx
        movl    S(,%rax,4), %eax
        xorl    state(%rcx), %eax
        movl    %eax, state(%rcx)
        mov     %eax, %eax
        xorl    S(,%rax,4), %edx
        movl    state+8(%rcx), %eax
        movl    %edx, state+4(%rcx)
        mov     %edx, %edx
        xorl    S(,%rdx,4), %eax
        movl    state+12(%rcx), %edx
        movl    %eax, state+8(%rcx)
        mov     %eax, %eax
        xorl    S(,%rax,4), %edx
        movl    %edx, state+12(%rcx)
        addq    $16, %rcx
        cmpq    $64, %rcx
        jne     .L2

with

.L2:
        mov     %edx, %eax
        movl    S(,%rax,4), %edx
        movl    state(%rcx), %eax
        xorl    %edx, %eax
        movl    state+4(%rcx), %edx
        movl    %eax, state(%rcx)
        movl    S(,%rax,4), %eax
        xorl    %edx, %eax
        movl    state+8(%rcx), %edx
        movl    %eax, state+4(%rcx)
        movl    S(,%rax,4), %eax
        xorl    %edx, %eax
        movl    state+12(%rcx), %edx
        xorl    S(,%rax,4), %edx
        movl    %eax, state+8(%rcx)
        movl    %edx, state+12(%rcx)
        addq    $16, %rcx
        cmpq    $64, %rcx
        jne     .L2

Ideally, SEE should remove zero-extension without adding new ones, like

.L2:
        mov     %edx, %eax
        movl    state+4(%rcx), %edx
        movl    S(,%rax,4), %eax
        xorl    state(%rcx), %eax
        movl    %eax, state(%rcx)
        xorl    S(,%rax,4), %edx
        movl    state+8(%rcx), %eax
        movl    %edx, state+4(%rcx)
        xorl    S(,%rdx,4), %eax
        movl    state+12(%rcx), %edx
        movl    %eax, state+8(%rcx)
        xorl    S(,%rax,4), %edx
        movl    %edx, state+12(%rcx)
        addq    $16, %rcx
        cmpq    $64, %rcx
        jne     .L2

H.J.



More information about the Gcc-patches mailing list