Elimination of duplicate sign extensions

Mark Shinwell shinwell@codesourcery.com
Wed Sep 12 15:27:00 GMT 2007


Andrew Pinski wrote:
> On 9/11/07, Mark Shinwell <shinwell@codesourcery.com> wrote:
>> This patch, based on one by Nigel Stephens of MIPS Technologies,
>> eliminates some duplicate sign extensions upon function calls.
>> Currently, if we have something such as:
>>
>> static int f(short foobar)
>> {
>>    return foobar > 0;
>> }
>>
> 
> Does this optimization fix PR 23450 ?

Before my patch your second example in that PR gives:

f:
         pushl   %ebp
         addl    $1, %eax
         movl    %esp, %ebp
         movsbl  %al,%eax
         popl    %ebp
         ret
         .size   f, .-f
         .p2align 4,,15
.globl g
         .type   g, @function
g:
         pushl   %ebp
         movl    %esp, %ebp
         movzbl  8(%ebp), %eax
         addl    $1, %eax
         movsbl  %al,%eax
         call    f
         popl    %ebp
         movsbl  %al,%eax
         ret

and after the patch we get:

f:
         pushl   %ebp
         addl    $1, %eax
         movl    %esp, %ebp
         popl    %ebp
         ret
         .size   f, .-f
         .p2align 4,,15
.globl g
         .type   g, @function
g:
         pushl   %ebp
         movl    %esp, %ebp
         movzbl  8(%ebp), %eax
         popl    %ebp
         addl    $1, %eax
         movsbl  %al,%eax
         jmp     f

So it certainly helps -- but not being an x86 expert I'm not
sure offhand if this is addressing the entirety of that PR.

On x86_64-unknown-linux-gnu, it seems that the sign extensions at
the head of functions are already being elided for some reason.

Mark



More information about the Gcc-patches mailing list