Different Runtimes using clang-gcc and clang-opt-llc-gcc

Hello,

  I have trouble compiling programs using clang on Ubuntu-Natty
(getting some linker errors). So I generated a object file using "-c"
and then used gcc to generate the final executable. It worked fine.

I tried the following method also:

$ clang -O0 -c -flto foo.c
$ llc foo.o
$ gcc foo.o.s

It also worked. However the problem is I am getting different runtimes
using the two different methods. The executable generated using the
second method is running faster than the one generated using the first
method. I am confused as in both cases I am using -O0.

In general if I want measure runtimes which of the two methods is more accurate.

Thanks in advance.
-Suresh

PS: Is there any fix for the linker errors generated by clang on Natty.

Hi Suresh,

$ clang -O0 -c -flto foo.c
$ llc foo.o

^ llc defaults to -O2

$ gcc foo.o.s

Ciao, Duncan.

Hi Suresh,

$ clang -O0 -c -flto foo.c
$ llc foo.o

^ llc defaults to -O2

Yep. Exactly right. Specifically, the code generator and register allocator behave differently at -O0, sacrificing generated code quality to get better debugging information and compile-time performance. That said, running things this way, most of the mid-level optimizations that would normally be applied at -O2 still aren't as they're not part of llc.