[AOT] Memory Info Restore Mechanism with Better Performance #4113
+171
−150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found that my program runs slower in WAMR AOT mode compared to other WASM runtimes, e.g. WAVM. I compared their LLVM IRs and found that WAMR emits more load operations of memory base.
In WAMR, functions with
mem_space_unchanged
keep memory base address inmem_base_addr
ofAOTMemInfo
, while others keep the address of memory base address in that field. When emit instructions like load/store, the former use the base address directly, while the later should load base address from its address at first. This reload is redundant when there is no possibility of changing memory between two consecutive load/store instructions:Optimization passes won’t recognize this redundancy because the reloaded memory base is accessed within the context.
In WAVM, the base address is reloaded when the memory possibly changes, e.g. after calling another function or after
memory.grow
. This can be redundant if there are no subsequent load/store instructions, but the dead code elimination pass handles this:Performance
Here is a sample C++ program
substr.cc
:Compiled with emcc (version:
3.1.59 (0e4c5994eb5b8defd38367a416d0703fd506ad81)
)Then ran wamrc and iwasm(linux) and compared the performance:
product-mini/platforms/posix/main.c:
result:
commit e3dcf4f
commit 3f268e5
IR(optimized) comparison: