Void vs int

Is it more efficient to return void rather than the int 0, e.g. does it reduce
register pressure?

"ret void" and "ret i32 undef" should lead to exactly the same code on
any architecture; returning zero is slightly more expensive, but
shouldn't affect register pressure.

-Eli

If you don't use the value after the call, then it will produce the same LLVM code for both functions from llvm-gcc and clang:

$ cat t.c
int foo();

void bar() {
  foo();
}

void baz();

void qux() {
  baz();
}

$ llvm-gcc -o - -S t.c -mllvm -disable-llvm-optzns -emit-llvm

define void @bar() nounwind ssp {
entry:
  %0 = call i32 (...)* @foo() nounwind ; <i32> [#uses=0]
  br label %return

return: ; preds = %entry
  ret void
}

declare i32 @foo(...)

define void @qux() nounwind ssp {
entry:
  call void (...)* @baz() nounwind
  br label %return

return: ; preds = %entry
  ret void
}

$ clang -o - -S t.c -emit-llvm

define void @bar() nounwind ssp {
entry:
  %call = call i32 (...)* @foo() ; <i32> [#uses=0]
  ret void
}

declare i32 @foo(...)

define void @qux() nounwind ssp {
entry:
  call void (...)* @baz()
  ret void
}

So there should be no advantage in this situation. However, if you use the "int 0" value, then it will produce different code for the two functions. And then the register allocator will have to get involved.

Caveat: This was tested on a Mac.

-bw