[LLVMdev] LLVM Execution engine: Native call vs LLVM IR function call

nlamee at cs.mcgill.ca nlamee at cs.mcgill.ca
Wed Mar 27 21:52:54 PDT 2013


Hi,

I would like to understand why calling a native function from a function
in LLVM IR can be much faster than calling an equivalent function in LLVM
IR.

For instance, here are two equivalent programs. The first calls an llvm
function while the second calls a native function. On my AMD machine, the
first takes 4.48s to run while the second takes 3.49s.

define i64 @bloop() {
entry:
  br label %bb1

bb1:                                              ; preds = %cont, %entry
  %0 = phi i64 [ 0, %entry ], [ %3, %cont ]
  %1 = phi i64 [ 0, %entry ], [ %res, %cont ]
  %2 = icmp ugt i64 %0, 1000000001
  br i1 %2, label %exit, label %cont

exit:                                             ; preds = %bb1
  ret i64 %1

cont:                                             ; preds = %bb1
  %3 = add i64 %0, 1
  %res = call i64 @sqr(i64 %0)
  br label %bb1
}

define i64 @sqr(i64 %arg1) {
entry:
  %0 = mul i64 %arg1, %arg1
  ret i64 %0
}

=============================================


define i64 @bnative() {
entry:
  br label %bb1

bb1:                                              ; preds = %cont, %entry
  %0 = phi i64 [ 0, %entry ], [ %3, %cont ]
  %1 = phi i64 [ 0, %entry ], [ %res, %cont ]
  %2 = icmp ugt i64 %0, 1000000001
  br i1 %2, label %exit, label %cont

exit:                                             ; preds = %bb1
  ret i64 %1

cont:                                             ; preds = %bb1
  %3 = add i64 %0, 1
  %res = call i64 @cppnative(i64 %0)
  br label %bb1
}

C++:

long cppNative(long data) {
  return data*data;
}

I am using g++ 4.5.2. I will appreciate any help.

Thank you.

Best regards,
Nurudeen.




More information about the llvm-dev mailing list