Skip to content

Remove MOVE $$locbase, $$sp if non-entry function doesn't use stack#7548

Merged
ironcev merged 12 commits intomasterfrom
ironcev/remove-setting-locbase
Feb 12, 2026
Merged

Remove MOVE $$locbase, $$sp if non-entry function doesn't use stack#7548
ironcev merged 12 commits intomasterfrom
ironcev/remove-setting-locbase

Conversation

@ironcev
Copy link
Member

@ironcev ironcev commented Feb 8, 2026

Description

This PR:

If the function does not use stack at all, the $$locbase is never used, by definition.

Not using stack at all means that the function:

  • does not have any locals
  • does not call any functions that spill arguments to the stack
  • does not spill any registers to the stack when allocating registers

Having MOVE $$locbase, $$sp in entry functions is a part of compiler's contract and tooling relies on it. Therefore, MOVE $$locbase, $$sp remains in entry functions even if $$locbase is not used.

On the contrary, in non-entry functions, setting $$locbase is an implementation detail no tooling relies on. E.g. a forc debug or similar.

Additionally, the PR:

  • groups function prologue and epilogue instructions into [fn/entry init/end] groups for better readability and easier analysis of ASM. Also, it opens the way towards better automatic analysis of ASM output if needed in the future.

  • adapts filter-fn to use the new [fn/entry init/end: <fn name>]comments.

  • Fixes Register pressure makes compiler panic in register_allocator::spill #7547.

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).
  • I have added tests that prove my fix is effective or that my feature works.
  • 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.

@ironcev ironcev self-assigned this Feb 8, 2026
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: codegen Everything to do with IR->ASM, register allocation, etc. labels Feb 8, 2026
@ironcev
Copy link
Member Author

ironcev commented Feb 8, 2026

👍

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 8, 2026

Merging this PR will degrade performance by 20.27%

❌ 1 regressed benchmark
✅ 24 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
tokens_for_program 522.6 µs 655.5 µs -20.27%

Comparing ironcev/remove-setting-locbase (f8651cf) with master (c6d0d12)

Open in CodSpeed

@ironcev ironcev marked this pull request as ready for review February 10, 2026 11:44
@ironcev ironcev requested a review from a team as a code owner February 10, 2026 11:44
@cursor
Copy link

cursor bot commented Feb 10, 2026

PR Summary

Medium Risk
Touches core Fuel codegen and register-allocation/optimization pipelines; while behavior should be equivalent, incorrect stack-usage detection or metadata plumbing could change generated bytecode and tooling assumptions.

Overview
Reduces generated Fuel VM bytecode by dropping redundant function prologue setup: MOVE $$locbase, $$sp is now removed for non-entry functions proven to not use the stack (detected via CFEI 0), while keeping the instruction for entry functions to preserve tooling expectations.

To support this and improve debuggability, instruction sets now carry optional (function name, is_entry) metadata through register allocation/optimization, and emitted ASM comments are standardized into [entry|fn init/end: <name>] groups (calls and returns included). This refactors the Fuel register allocator API to return Vec<AllocatedAbstractOp>, adds Value::get_parent_function(), updates module accessors, and refreshes affected e2e snapshots plus a new no_locbase optimization test.

Written by Cursor Bugbot for commit f8651cf. This will update automatically on new commits. Configure here.

@ironcev ironcev requested a review from xunilrj February 10, 2026 11:44
@ironcev ironcev enabled auto-merge (squash) February 10, 2026 11:45
@ironcev
Copy link
Member Author

ironcev commented Feb 10, 2026

Comparing 'e2e-gas-usages':

Improvements Regressions
Count 268
Average 1.65%
Median 1.61%
Max 8.22%
Min 0.01%

Comparing 'e2e-bytecode-sizes':

Improvements Regressions
Count 188
Average 5.09%
Median 2.86%
Max 12.50%
Min 0.03%

Comparing 'in-language-gas-usages':

Improvements Regressions
Count 418
Average 1.43%
Median 1.37%
Max 4.44%
Min 0.01%

Comparing 'bytecode-sizes' for project 'o2':

Improvements Regressions
Count 12
Average 0.14%
Median 0.12%
Max 0.21%
Min 0.09%

Comparing 'gas-usages' for project 'o2':

Improvements Regressions
Count 65
Average 0.06%
Median 0.04%
Max 1.69%
Min 0.02%

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@ironcev ironcev merged commit 0d09a28 into master Feb 12, 2026
47 checks passed
@ironcev ironcev deleted the ironcev/remove-setting-locbase branch February 12, 2026 10:05
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. compiler General compiler. Should eventually become more specific as the issue is triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Register pressure makes compiler panic in register_allocator::spill

3 participants

Comments