Skip to content

[WIP] [opt] let OptimizeAddedConstants handle memory64 well #5043

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

Merged
merged 7 commits into from
Sep 21, 2022

Conversation

dongAxis
Copy link
Contributor

hi all,

When program is compile with wasm64, the addr and offset of load and store should be i64.

But OptimizeAddedConstants dose not handle well, so I use this patch to fix that.
Sample wasm will attached.

Best Regards
Yifeng

@dongAxis dongAxis changed the title [opt] let OptimizeAddedConstants handle memory64 well [WIP] [opt] let OptimizeAddedConstants handle memory64 well Sep 15, 2022
@dongAxis
Copy link
Contributor Author

Since it is wip MR, so i do not write unit test. If this patch accept, I will write more unit test

@dongAxis
Copy link
Contributor Author

dongAxis commented Sep 15, 2022

attached sample file.
When we use binaryen to optimize this file, we will got an assert failed.
cmd line: wasm-opt -- --strip-dwarf --post-emscripten -O3 --low-memory-unused --zero-filled-memory --strip-producers a.out.wasm -o a.out.wasm.opt --detect-features
The backtrace will look like:
image

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Thanks!

In addition to the comments below please also add a test. Perhaps in a new file, test/lit/passes/optimize-added-constants-memory64.wast.

Copy link
Contributor

@MATRIXKOO MATRIXKOO left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@MATRIXKOO MATRIXKOO left a comment

Choose a reason for hiding this comment

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

LGTM

@MATRIXKOO
Copy link
Contributor

// /src/src/passes/OptimizeAddedConstants.cpp:242:15 looks like `value >=0` always true.
 uint64_t value = literal.getInteger();
 // Avoid uninteresting corner cases with peculiar offsets.
 if (value >= 0 && value < PassOptions::LowMemoryBound) {

@dongAxis dongAxis force-pushed the fix_MemoryAccessOptimizer branch from 5e6409e to 7137875 Compare September 20, 2022 12:26
@dongAxis
Copy link
Contributor Author

@kripken In addition, could you give me a write permission? Because we will focus on binaryen and wasm, I would love to write more code for binaryen. Thanks in advance.

@dongAxis
Copy link
Contributor Author

@kripken In addition, could you give me a write permission? Because we will focus on binaryen and wasm, I would love to write more code for binaryen. Thanks in advance.

Hi kripken, I found some of unit test failed, could you tell me how to run those tests in my local environment? thanks

@kripken
Copy link
Member

kripken commented Sep 20, 2022

Hmm, the CI error looks unrelated to this PR. It's a closure error,

building:ERROR: Closure compiler completed with warnings and -Werror=closure enabled, aborting!

Likely that is due to @sbc100's recent changes on emscripten (CI here uses latest unstable emscripten). Does that sound likely @sbc100 ?

@dongAxis In general though to run those tests you can look at .github/workflows/ci.yml, and I think it just installs the emsdk and runs ./scripts/emcc-tests.sh. But in this case we can ignore that failure.

About write access, I think the main issue was that github wouldn't run CI for you without someone approving it? That seems to have been fixed after your earlier commits that landed - I didn't need to manually run CI here today. I believe github requires manual approval for CI only for people that haven't committed to a repo.

@sbc100
Copy link
Member

sbc100 commented Sep 20, 2022

Hmm, the CI error looks unrelated to this PR. It's a closure error,

building:ERROR: Closure compiler completed with warnings and -Werror=closure enabled, aborting!

Likely that is due to @sbc100's recent changes on emscripten (CI here uses latest unstable emscripten). Does that sound likely @sbc100 ?

Yup that sounds expected. I guess we should either fix the warnings of build with -Wno-closure to disable them.

@dongAxis
Copy link
Contributor Author

Hmm, the CI error looks unrelated to this PR. It's a closure error,

building:ERROR: Closure compiler completed with warnings and -Werror=closure enabled, aborting!

Likely that is due to @sbc100's recent changes on emscripten (CI here uses latest unstable emscripten). Does that sound likely @sbc100 ?

@dongAxis In general though to run those tests you can look at .github/workflows/ci.yml, and I think it just installs the emsdk and runs ./scripts/emcc-tests.sh. But in this case we can ignore that failure.

About write access, I think the main issue was that github wouldn't run CI for you without someone approving it? That seems to have been fixed after your earlier commits that landed - I didn't need to manually run CI here today. I believe github requires manual approval for CI only for people that haven't committed to a repo.

ok thanks

@dongAxis dongAxis force-pushed the fix_MemoryAccessOptimizer branch from 2092ce9 to cc78ca8 Compare September 20, 2022 16:11
@kripken kripken merged commit 7fb6cfb into WebAssembly:main Sep 21, 2022
@kripken
Copy link
Member

kripken commented Sep 21, 2022

About memory64 performance, this PR fixes one important issue, and there are likely more places we just support 32-bit integers but not 64. I bet in OptimizeInstructions for example we have such issues. One way to find them might be to compile the same code in wasm32 and wasm64 and just look at the code side by side - anywhere the wasm64 code is larger is worth investigating.

cc @sbc100

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.

5 participants