Skip to content

Commit 30cb05f

Browse files
authored
Refine llvm pass order (#948)
Put Vectorize passes before GVN/LICM passes as normally the former gains more performance improvement and the latter might break the optimizations for the former. Can improve performance of several sightglass cases. And don't check exception throw after calling an AOT function if it is and recursive call, similar to handing of Spec tail call opcode.
1 parent 6bcf048 commit 30cb05f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

core/iwasm/compilation/aot_emit_function.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
560560
goto fail;
561561
}
562562
else {
563+
bool recursive_call =
564+
(func_ctx == func_ctxes[func_idx - import_func_count]) ? true
565+
: false;
566+
563567
if (comp_ctx->is_indirect_mode) {
564568
LLVMTypeRef func_ptr_type;
565569

@@ -603,7 +607,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
603607

604608
/* Check whether there was exception thrown when executing
605609
the function */
606-
if (!tail_call && !check_exception_thrown(comp_ctx, func_ctx))
610+
if (!tail_call && !recursive_call
611+
&& !check_exception_thrown(comp_ctx, func_ctx))
607612
goto fail;
608613
}
609614

core/iwasm/compilation/aot_llvm.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ create_cur_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
500500

501501
offset = I32_CONST(offsetof(AOTModuleInstance, cur_exception));
502502
func_ctx->cur_exception = LLVMBuildInBoundsGEP(
503-
comp_ctx->builder, func_ctx->aot_inst, &offset, 1, "cur_execption");
503+
comp_ctx->builder, func_ctx->aot_inst, &offset, 1, "cur_exception");
504504
if (!func_ctx->cur_exception) {
505505
aot_set_last_error("llvm build in bounds gep failed.");
506506
return false;
@@ -1877,6 +1877,8 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
18771877
aot_set_last_error("create LLVM target machine failed.");
18781878
goto fail;
18791879
}
1880+
1881+
LLVMSetTarget(comp_ctx->module, triple_norm);
18801882
}
18811883

18821884
if (option->enable_simd && strcmp(comp_ctx->target_arch, "x86_64") != 0
@@ -1935,6 +1937,11 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
19351937
LLVMAddIndVarSimplifyPass(comp_ctx->pass_mgr);
19361938

19371939
if (!option->is_jit_mode) {
1940+
/* Put Vectorize passes before GVN/LICM passes as the former
1941+
might gain more performance improvement and the latter might
1942+
break the optimizations for the former */
1943+
LLVMAddLoopVectorizePass(comp_ctx->pass_mgr);
1944+
LLVMAddSLPVectorizePass(comp_ctx->pass_mgr);
19381945
LLVMAddLoopRotatePass(comp_ctx->pass_mgr);
19391946
LLVMAddLoopUnswitchPass(comp_ctx->pass_mgr);
19401947
LLVMAddInstructionCombiningPass(comp_ctx->pass_mgr);
@@ -1944,11 +1951,9 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
19441951
disable them when building as multi-thread mode */
19451952
LLVMAddGVNPass(comp_ctx->pass_mgr);
19461953
LLVMAddLICMPass(comp_ctx->pass_mgr);
1954+
LLVMAddInstructionCombiningPass(comp_ctx->pass_mgr);
1955+
LLVMAddCFGSimplificationPass(comp_ctx->pass_mgr);
19471956
}
1948-
LLVMAddLoopVectorizePass(comp_ctx->pass_mgr);
1949-
LLVMAddSLPVectorizePass(comp_ctx->pass_mgr);
1950-
LLVMAddInstructionCombiningPass(comp_ctx->pass_mgr);
1951-
LLVMAddCFGSimplificationPass(comp_ctx->pass_mgr);
19521957
}
19531958

19541959
/* Create metadata for llvm float experimental constrained intrinsics */
@@ -2608,4 +2613,4 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
26082613
}
26092614

26102615
return const_value;
2611-
}
2616+
}

0 commit comments

Comments
 (0)