Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove indirect-load for constants on Xtensa Target to improve performance #4162

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

dongsheng28849455
Copy link
Contributor

@dongsheng28849455 dongsheng28849455 commented Mar 25, 2025

In XIP mode on Xtensa platform, compared with non XIP, there may be some performance degradation. The Coremark test results on the ESP32/Nuttx platform are:

Non-XIP: 114.94
XIP: 83

According to the handling of constants by the Xtensa backend, even without indrect load, there will be no relocation. Because the backend does not perform fixup processing on immediate numbers when processing jump/branch instructions, Refer to getL32RTargetEncoding
So for the Xtensa platform, the indirct loading is not so necessary, after removing it, the performance is improve as below(Coremark):

Opt XIP: 112.9

@@ -12,6 +12,7 @@ aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
{
LLVMValueRef value;

#if !defined(BUILD_TARGET_XTENSA)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about implement this by modify the intrinsic flags instead?

else if (!strncmp(comp_ctx->target_arch, "xtensa", 6)) {
/*
* Note: Use builtin intrinsics since hardware float operation
* will cause rodata relocation
*/
add_f32_common_intrinsics(comp_ctx);
add_i32_common_intrinsics(comp_ctx);
add_f64_common_intrinsics(comp_ctx);
add_i64_common_intrinsics(comp_ctx);
add_common_float_integer_conversion(comp_ctx);
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST);
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST);
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_CONST);
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_CONST);
}

@@ -347,7 +347,9 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,

POP_F32(value);

#if !defined(BUILD_TARGET_XTENSA)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about add more intrinsic flags for conversions?

}
else {
if (comp_ctx->is_indirect_mode
&& aot_intrinsic_check_capability(comp_ctx, "f32.const")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there ought to be a function to eliminate a particular intrinsic capability, such as remove_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CMP)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants