gcc -S vs clang -S

Olivier Galibert galibert@pobox.com
Tue May 12 13:18:00 GMT 2015


Note that at -O3 there is a difference still:
clang (3.6.0):
        addl    %esi, %edi
        movl    %edi, %eax
        retq

gcc (4.9.2)
        leal    (%rdi,%rsi), %eax
        ret

Can't tell which is best, if any.

  OG.


On Tue, May 12, 2015 at 4:06 AM,  <pinskia@gmail.com> wrote:
>
>
>
>
>> 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