This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc -S vs clang -S
- From: Olivier Galibert <galibert at pobox dot com>
- To: pinskia at gmail dot com
- Cc: Thiago Farina <tfransosi at gmail dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Tue, 12 May 2015 15:18:46 +0200
- Subject: Re: gcc -S vs clang -S
- Authentication-results: sourceware.org; auth=none
- References: <CACnwZYe=psc2jqUeva3ZxFHvADz3D7SHqRAVyGcHyVOuRca+NA at mail dot gmail dot com> <8AF3EC7F-E86D-462D-8E07-B51162E9271E at gmail dot com>
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