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

Optimize shadow stack instruction sequences #928

Open
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

Robbepop
Copy link
Collaborator

@Robbepop Robbepop commented Feb 6, 2024

Closes #920.

TODOs

  • Fuse i32.add_imm with global.set 0
  • Fuse global.get 0 with i32.add_imm
  • Fuse fused global.get 0 + i32.add_imm with i32.local_tee and global.set 0
  • Support fusion of i32.add with a function local constant rhs register.

@paritytech-cicd-pr

This comment was marked as outdated.

@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2024

Codecov Report

Attention: Patch coverage is 77.57848% with 50 lines in your changes are missing coverage. Please review.

Project coverage is 81.79%. Comparing base (f626385) to head (15cd321).

Files Patch % Lines
...rates/wasmi/src/engine/translator/instr_encoder.rs 72.88% 16 Missing ⚠️
crates/wasmi/src/engine/executor/instrs/global.rs 30.00% 14 Missing ⚠️
crates/wasmi/src/engine/translator/visit.rs 55.00% 9 Missing ⚠️
crates/wasmi/src/engine/executor/instrs.rs 33.33% 4 Missing ⚠️
...ates/wasmi/src/engine/translator/visit_register.rs 0.00% 3 Missing ⚠️
crates/wasmi/src/engine/translator/mod.rs 90.00% 2 Missing ⚠️
...rates/wasmi/src/engine/translator/relink_result.rs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #928      +/-   ##
==========================================
- Coverage   81.79%   81.79%   -0.01%     
==========================================
  Files         262      262              
  Lines       24302    24499     +197     
==========================================
+ Hits        19878    20039     +161     
- Misses       4424     4460      +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Robbepop Robbepop mentioned this pull request Feb 8, 2024
This fixes a bug with a niche value when rhs=i16::MIN since there is no symmetric equivalent for -i16::MIN that fits inside an i16 value. This made the optimization fail for rhs=i16::MIN. By always compiling isub as iadd with negated rhs value we avoid this situation gracefully.
@Robbepop
Copy link
Collaborator Author

Robbepop commented Mar 14, 2024

Comment on why this has not yet been merged despite passing all CI tests and working: it introduces a lot of complexity into the translation pipelined compared to the gains we see and can verify. The runtime gains are mostly single digits and restricted to sets of benchmarks that actually make use of the shadow stack. The global_bump benchmark is heavily affected with roughly 30% performance improvement but it is also very artificial. On the flip side the improvements to memory consumption also exist but are also just single digits for practical Wasm binaries.

So all in all the question is whether the gains are worth the added complexities.

@Robbepop
Copy link
Collaborator Author

The miri CI job fails because of this issue: rust-lang/miri#3404

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.

Optimization: Special handling for common shadow stack instruction sequences
3 participants