[LLVMdev] Query on optimizing away function calls.

Mahadevan R mdevan.foobar at gmail.com
Thu Jun 18 00:29:24 PDT 2009


Hi all.

Consider the following code:

------------
define void @func() {
   %a = alloca i32
   store i32 42, i32* %a
   call void @func2(i32* %a) nounwind
   ret void
}

define void @func2(i32* %a) nounwind {
   store i32 43, i32* %a
   ret void
}
------------

It is possible to optimize this to:

------------
define void @func() {
       ret void
}

define void @func2(i32* %a) nounwind {
       store i32 43, i32* %a
       ret void
}
------------

which is just what I want. However, if @func2 is implemented in an external C
library, is this not possible? Specifically, while optimizing:

------------
define void @func() {
   %a = alloca i32
   store i32 42, i32* %a
   call void @func2(i32* %a) nounwind
   ret void
}

declare void @func2(i32* %a) nounwind
------------

is there some way to specify that @func2 only modifies values accessible via %a,
so that if all those values are ultimately discarded then the call to @func2
itself can be discarded?

The "readonly" function attribute looks to be too strict for this.

Or am I missing something obvious?

Thanks In Advance,
-Mahadevan.



More information about the llvm-dev mailing list