gcc -S vs clang -S

pinskia@gmail.com pinskia@gmail.com
Tue May 12 02:07:00 GMT 2015





> On May 11, 2015, at 6:16 PM, Thiago Farina <tfransosi@gmail.com> wrote:
> 
> Hi,
> 
> Clang 3.7 generated the following code:
> 
> $ clang -S -O0 -fno-unwind-tables -fno-asynchronous-unwind-tables
> add.c -o add_att_x64.s
> 
> add:
>         pushq   %rbp
>         movq    %rsp, %rbp
>         movl    %edi, -4(%rbp)
>         movl    %esi, -8(%rbp)
>         movl    -4(%rbp), %esi
>         addl    -8(%rbp), %esi
>         movl    %esi, %eax
>         popq    %rbp
>         retq
> 
> While gcc 4.8 generated the following:
> 
> $ gcc -S -O0 -fno-unwind-tables -fno-asynchronous-unwind-tables add.c
> -o add_att_x64.s
> 
> add:
>        pushq   %rbp
>        movq    %rsp, %rbp
>        movl    %edi, -4(%rbp)
>        movl    %esi, -8(%rbp)
>        movl    -8(%rbp), %eax
>        movl    -4(%rbp), %edx
>        addl    %edx, %eax
>        popq    %rbp
>        ret
> 
> $ cat add.c
> int add(int a, int b) {
>        return a + b;
> }
> 
> Is the clang version better?

Neither is better or worse due to this is at -O0. 

Thanks,
Andrew

> 
> -- 
> Thiago Farina



More information about the Gcc mailing list