[LLVMdev] Query on optimizing away function calls.

Duncan Sands baldrick at free.fr
Thu Jun 18 05:23:46 PDT 2009


Hi,

> Here's where this question comes from, may be this use case inspires
> someone :-). I've a "big.int", that should behave like an i32. The
> big.int routines are provided by a C runtime. To illustrate:
> 
> ----------------------
> ; int func(int a, int b) { int c = a; return b; }
> 
> ; using a regular int
> define i32 @func1(i32 %a, i32 %b) {
>     %cp = alloca i32
>     store i32 %a, i32* %cp
>     ret i32 %b
> }
> 
> %big.int = type { i32, i32, i32* }
> 
> ; using this big.int
> define %big.int* @func2(%big.int* %a, %big.int* %b) {
>     %cp = alloca %big.int
>     call void @big.int.copy.ctor(%big.int* %cp, %big.int* %b) nounwind
>     call void @big.int.dtor(%big.int* %cp) nounwind
>     ret %big.int* %b
> }
> 
> declare void @big.int.copy.ctor(%big.int*, %big.int*) nounwind
> declare void @big.int.dtor(%big.int*) nounwind
> ----------------------
> 
> LLVM being able to optimize away the unnecessary temp object would be a
> big win here.

I don't see how it can be.  Presumably the @big.int.dtor really does
something, like freeing memory.  It has to be run, no?

Ciao,

Duncan.



More information about the llvm-dev mailing list