I have a simple c code:
// main.c
#include <stdio.h>
void foo()
{
}
int main()
{
return 0;
}
Output of following command
clang -O3 -emit-llvm -c main.c -o main.bc; llc main.bc -o main.S; cat main.S;
I get:
...
foo: # @foo
.cfi_startproc
# %bb.0:
retq
...
This is what is expected. The foo()
function has been converted to retq
instruction.
But if I run the following command:
clang -emit-llvm -c main.c -o main.bc; llc -O=3 main.bc -o main.S; cat main.S;
I get:
...
foo: # @foo
.cfi_startproc
# %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
popq %rbp
.cfi_def_cfa %rsp, 8
retq
...
Functionally this is okay but foo()
in this case is unnecessary dealing with frame-pointer for an empty function. The difference between first case and second case is that in first case, we used -O3 for clang whereas in second case we used -O3 for llc. I would thought these two to be equivalent.
I also tried the following:
clang -emit-llvm -fomit-frame-pointer -c main.c -o main.bc ; llc -O=3 main.bc -o main.S; cat main.S;
And I get:
...
foo: # @foo
.cfi_startproc
# %bb.0:
retq
...
So, does this means if clang
decides to emit frame pointers into the LLVM bytecode, llc
is not smart enough to remove them? (llc
doesn't seem to have a -fomit-frame-pointer
option though it does have -disable-fp-elim
option which Disable frame pointer elimination optimization
so I would think llc is capable to eliminating frame pointers)