Skip to content

Conversation

@Dentosal
Copy link
Member

@Dentosal Dentosal commented Apr 23, 2025

Description

This PR adds an initial support to symbolic fuel-vm interpretation to improve codegen. The symbolic execution is designed to be extended in later PRs. In it's current form, it provides three distinct improvements:

  1. If a temporary (allocated) register contains a value already held in another register, we can use that other register instead. This reduces register pressure, and removes unnecessary mov ops.
  2. If a register already has the value we're setting it to, we can eliminate the instruction doing so.
  3. For conditional jump instructions, if the value of the condition is known, one of the branches can be elminated. In such cases, the instruction is either removed or replaced with an unconditional jump. Dead code elimination pass can then potentially remove the now-unreachable branch.

In addition to these changes, this PR takes the optimization level into account for asm generation. For debug builds, we only run the optimization passes once. But for release builds we run the optimization passes multiple times, until we either cannot eliminate any more operations, or until a fixed upper limit of rounds. For instance, this means that if the new pass added in this PR manages to eliminate a branch, and then dead code elimination removes that code, it could allow the interpretation pass to do even more work.

To account for new optimization passes, I also organized them to mulple files, so that the ones which create private types are scoped well and thus easier to read.

Impact

project size before size after size reduction
mira-v1-core 89.384 KB 83.480 KB 6.6%

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book). No changes required!
  • I have added tests that prove my fix is effective or that my feature works. Just updated pre-existing ones!
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@Dentosal Dentosal added the compiler: codegen Everything to do with IR->ASM, register allocation, etc. label Apr 23, 2025
@Dentosal Dentosal self-assigned this Apr 23, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Apr 23, 2025

CodSpeed Performance Report

Merging #7109 will not alter performance

Comparing dento/asm-gen-opt (2143ccd) with master (804c4a4)

Summary

✅ 22 untouched benchmarks

vaivaswatha
vaivaswatha previously approved these changes Apr 26, 2025
vaivaswatha
vaivaswatha previously approved these changes Apr 29, 2025
@Dentosal Dentosal temporarily deployed to fuel-sway-bot May 2, 2025 17:54 — with GitHub Actions Inactive
@Dentosal Dentosal requested a review from vaivaswatha May 2, 2025 18:20
@JoshuaBatty JoshuaBatty enabled auto-merge (squash) May 5, 2025 05:12
@JoshuaBatty JoshuaBatty merged commit 1c885cf into master May 5, 2025
41 checks passed
@JoshuaBatty JoshuaBatty deleted the dento/asm-gen-opt branch May 5, 2025 07:50
@Dentosal Dentosal mentioned this pull request May 12, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler: codegen Everything to do with IR->ASM, register allocation, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants