nlamee at cs.mcgill.ca
2013-Mar-28 04:52 UTC
[LLVMdev] LLVM Execution engine: Native call vs LLVM IR function call
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.
Óscar Fuentes
2013-Mar-28 11:05 UTC
[LLVMdev] LLVM Execution engine: Native call vs LLVM IR function call
nlamee at cs.mcgill.ca writes:> 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.Do you optimize the LLVM IR? The IR version can inline the call and just that would make it faster than the "native" version. Please describe how do you compile your LLVM IR. Once knowing that, if you optimize the IR and it still slower, the real answer should pop up by looking at the assembler.
nlamee at cs.mcgill.ca
2013-Mar-28 14:40 UTC
[LLVMdev] LLVM Execution engine: Native call vs LLVM IR function call
Hi Óscar, Thank you for your response. I did not explicitly optimize the IR. I compile and run the two versions with ... GenericValue gv = EE->runFunction(bsqr, args); ... GenericValue gv2 = EE->runFunction(cppnat, args); I am calling method runFunction of ExecutionEngine. I am using the default code gen optimization level. Best regards, Nurudeen. On Thu, March 28, 2013 7:05 am, Ãscar Fuentes wrote:> nlamee at cs.mcgill.ca writes: > >> 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. >> > > Do you optimize the LLVM IR? The IR version can inline the call and just > that would make it faster than the "native" version. > > Please describe how do you compile your LLVM IR. > > > Once knowing that, if you optimize the IR and it still slower, the real > answer should pop up by looking at the assembler. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
Apparently Analagous Threads
- [LLVMdev] LLVM Execution engine: Native call vs LLVM IR function call
- [LLVMdev] LLVM Execution engine: Native call vs LLVM IR function call
- [LLVMdev] Seg faulting on vector ops
- [LLVMdev] Execution Engine: CodeGenOpt level
- [LLVMdev] Seg faulting on vector ops