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.
This commit is contained in:
Wenyong Huang 2022-01-12 18:56:56 +08:00 committed by GitHub
parent 6bcf048523
commit 30cb05f223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -560,6 +560,10 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
goto fail; goto fail;
} }
else { else {
bool recursive_call =
(func_ctx == func_ctxes[func_idx - import_func_count]) ? true
: false;
if (comp_ctx->is_indirect_mode) { if (comp_ctx->is_indirect_mode) {
LLVMTypeRef func_ptr_type; LLVMTypeRef func_ptr_type;
@ -603,7 +607,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
/* Check whether there was exception thrown when executing /* Check whether there was exception thrown when executing
the function */ the function */
if (!tail_call && !check_exception_thrown(comp_ctx, func_ctx)) if (!tail_call && !recursive_call
&& !check_exception_thrown(comp_ctx, func_ctx))
goto fail; goto fail;
} }

View File

@ -500,7 +500,7 @@ create_cur_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
offset = I32_CONST(offsetof(AOTModuleInstance, cur_exception)); offset = I32_CONST(offsetof(AOTModuleInstance, cur_exception));
func_ctx->cur_exception = LLVMBuildInBoundsGEP( func_ctx->cur_exception = LLVMBuildInBoundsGEP(
comp_ctx->builder, func_ctx->aot_inst, &offset, 1, "cur_execption"); comp_ctx->builder, func_ctx->aot_inst, &offset, 1, "cur_exception");
if (!func_ctx->cur_exception) { if (!func_ctx->cur_exception) {
aot_set_last_error("llvm build in bounds gep failed."); aot_set_last_error("llvm build in bounds gep failed.");
return false; return false;
@ -1877,6 +1877,8 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
aot_set_last_error("create LLVM target machine failed."); aot_set_last_error("create LLVM target machine failed.");
goto fail; goto fail;
} }
LLVMSetTarget(comp_ctx->module, triple_norm);
} }
if (option->enable_simd && strcmp(comp_ctx->target_arch, "x86_64") != 0 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)
LLVMAddIndVarSimplifyPass(comp_ctx->pass_mgr); LLVMAddIndVarSimplifyPass(comp_ctx->pass_mgr);
if (!option->is_jit_mode) { if (!option->is_jit_mode) {
/* Put Vectorize passes before GVN/LICM passes as the former
might gain more performance improvement and the latter might
break the optimizations for the former */
LLVMAddLoopVectorizePass(comp_ctx->pass_mgr);
LLVMAddSLPVectorizePass(comp_ctx->pass_mgr);
LLVMAddLoopRotatePass(comp_ctx->pass_mgr); LLVMAddLoopRotatePass(comp_ctx->pass_mgr);
LLVMAddLoopUnswitchPass(comp_ctx->pass_mgr); LLVMAddLoopUnswitchPass(comp_ctx->pass_mgr);
LLVMAddInstructionCombiningPass(comp_ctx->pass_mgr); LLVMAddInstructionCombiningPass(comp_ctx->pass_mgr);
@ -1944,11 +1951,9 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
disable them when building as multi-thread mode */ disable them when building as multi-thread mode */
LLVMAddGVNPass(comp_ctx->pass_mgr); LLVMAddGVNPass(comp_ctx->pass_mgr);
LLVMAddLICMPass(comp_ctx->pass_mgr); LLVMAddLICMPass(comp_ctx->pass_mgr);
LLVMAddInstructionCombiningPass(comp_ctx->pass_mgr);
LLVMAddCFGSimplificationPass(comp_ctx->pass_mgr);
} }
LLVMAddLoopVectorizePass(comp_ctx->pass_mgr);
LLVMAddSLPVectorizePass(comp_ctx->pass_mgr);
LLVMAddInstructionCombiningPass(comp_ctx->pass_mgr);
LLVMAddCFGSimplificationPass(comp_ctx->pass_mgr);
} }
/* Create metadata for llvm float experimental constrained intrinsics */ /* Create metadata for llvm float experimental constrained intrinsics */