Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
I used both of these compilers in different projects.
How they are different in terms of code processing and output generations? For example both gcc
and clang
has -O2
options for optimization. Are they operating the same way (high level) in terms of optimizing code? I did a little test , for example if I have the following code:
int foo(int num) {
if(num % 2 == 1)
return num * num;
else
return num * num +1;
}
the following are the output assemblies with clang and gcc with -O2:
----gcc 5.3.0----- ----clang 3.8.0----
foo(int): foo(int):
movl %edi, %edx movl %edi, %eax
shrl $31, %edx shrl $31, %eax
leal (%rdi,%rdx), %eax addl %edi, %eax
andl $1, %eax andl $-2, %eax
subl %edx, %eax movl %edi, %ecx
cmpl $1, %eax subl %eax, %ecx
je .L5 imull %edi, %edi
imull %edi, %edi cmpl $1, %ecx
leal 1(%rdi), %eax setne %al
ret movzbl %al, %eax
.L5: addl %edi, %eax
movl %edi, %eax retq
imull %edi, %eax
ret
as it can be seen the output has different instructions. So my question is does one of them has advantage over another in different projects?