[LLVMdev] Forcing function inline not working

madiyaan ahmadsharif at hotmail.com
Wed Sep 16 18:55:02 PDT 2009

I have the following code:

static inline void foo() __attribute((always_inline));

int a;
static inline void foo()

int main(int argc, char *argv[])
  return 0;

However, the code generated by llvm 2.4 toolchain does not inline this
function. opt retains the function call. Here is the output when I try to
compile with -debug-only=inline:

..\..\..\win32\bin\win32\debug\opt.exe -O3 -debug-only=inline -mem2reg -f -o
test_opt.bc test.bc
Inliner visiting SCC: foo: 0 call sites.
Inliner visiting SCC: main: 1 call sites.
    Inlining: cost=always, Call:        call void (...)* @foo()
Inliner visiting SCC: INDIRECTNODE: 0 call sites.

Here is the .ll file:

; ModuleID = 'test_opt.bc'
target datalayout =
target triple = "i386-pc-win32"
@a = common global i32 0, align 4		; <i32*> [#uses=2]

define i32 @main(i32 %argc, i8** %argv) nounwind {
	tail call void (...)* @foo()
	ret i32 0

define internal void @foo(...) nounwind alwaysinline {
	%tmp = load i32* @a		; <i32> [#uses=1]
	%inc = add i32 %tmp, 1		; <i32> [#uses=1]
	store i32 %inc, i32* @a
	ret void

What am I doing wrong here? Is there a way to force a function to be inlined
by opt?

Best Regards,
View this message in context: http://www.nabble.com/Forcing-function-inline-not-working-tp25483934p25483934.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.

More information about the llvm-dev mailing list