[LLVMdev] Why clang inlines with -O3 flag and opt doesn't?

Duncan Sands baldrick at free.fr
Fri Sep 3 03:25:11 PDT 2010


Hi Yuri,

> When I compile my C fibonacci example fib.c with 'clang -O3 -c -emit-llvm -o fib-clang.bc fib.c&&   llvm-dis fib-clang.bc' I get fib-clang.ll that has some degree of inlining in it.

this is not exactly inlining, it is tail recursion elimination.

> But when I get an equivalent to fib.c file fib.ll and run it through opt with the command 'llvm-as fib.ll&&   opt -O3 fib.bc -o fib-opt.bc&&   llvm-dis fib-opt.bc' resulting fib-opt.ll doesn't have any degree of inlining despite the flag -O3.

It is not equivalent, because your C program returns 1 for the first Fibonacci
number, while the .ll returns 0.  If you change this

> spec:
>     %xcmp = icmp eq i32 %0, 1
>     %mres = zext i1 %xcmp to i32
>     ret i32 %mres

to

spec:
   return i32 1

then you get tail recursion elimination for the .ll too.

Ciao,

Duncan.



More information about the llvm-dev mailing list