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

ASM blocks handling: inlining, DCE, ASM returns without return register #6404

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

ironcev
Copy link
Member

@ironcev ironcev commented Aug 7, 2024

Description

This PR fixes #6332 and #6354 by:

  • including number of instructions in ASM blocks when calculating overall number of instructions for function inlining.
  • properly lowering ASM blocks that return unit, (), without return register to returning $zero in the ASM.

Additionally, the PR:

  • removes dead ASM blocks (that do not have side-effects) in the DCE pass.
  • prints ASM blocks that return () without a register as -> () to make it consistent with functions.
  • emits a warning if an ASM block is empty.
  • adds expressive diagnostic for UninitializedAsmRegShadowsItem warning and extends the warning for constants and configurables.
  • removes obsolete NamespaceAttributeDeprecated warning and its empty tests.
  • harmonizes and defines guidelines for ASM instruction comments.

Closes #6332.
Closes #6354.

Bytecode size changes

Changes in the fn-inline and dce optimizations had a minimal impact on the bytcode sizes of the should_pass test programs. Out of 455 tests, only 13 tests changed sizes. 8 tests got a size increase of 0.8% in average, while 5 tests got size decrease of 3.0% in average.

The real-world compolabs-orderbook contract got a minimal size decrease of 0.16%.

Click here for the numbers
Test Before After Decrease Percentage
empty_fields_in_storage_struct 28384 28456 -72 -0.25
language/deprecated_attribute 224 208 16 7.14
language/duplicated_storage_keys 224 208 16 7.14
language/references/dereferencing_operator_dot_on_structs 124920 125272 -352 -0.28
language/references/dereferencing_operator_dot_on_tuples 124920 125272 -352 -0.28
language/references/dereferencing_operator_index 92376 92344 32 0.03
language/references/dereferencing_operator_star 151152 151536 -384 -0.25
language/references/impl_reference_types 7840 7776 64 0.81
language/references/reassigning_via_references_passed_and_returned_to_and_from_functions 39008 39184 -176 -0.45
language/references/reassigning_via_references_to_expressions 36920 37064 -144 -0.39
language/references/reassigning_via_references_to_values 13952 13936 16 0.11
stdlib/storage_vec_insert 8480 8552 -72 -0.85
stdlib/vec_byte_remove 1904 1976 -72 -3.78

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 added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: ir IRgen and sway-ir including optimization passes compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: codegen Everything to do with IR->ASM, register allocation, etc. compiler: optimization IR Optimization Passes labels Aug 7, 2024
@ironcev ironcev self-assigned this Aug 7, 2024
Copy link

github-actions bot commented Aug 7, 2024

Benchmark for 3a8cc80

Click to view benchmark
Test Base PR %
code_action 5.0±0.10ms 5.3±0.09ms +6.00%
code_lens 293.2±10.66ns 284.2±7.80ns -3.07%
compile 2.7±0.04s 2.7±0.03s 0.00%
completion 4.6±0.10ms 4.7±0.03ms +2.17%
did_change_with_caching 2.6±0.03s 2.6±0.02s 0.00%
document_symbol 845.8±42.15µs 945.3±35.40µs +11.76%
format 71.7±1.19ms 72.3±0.59ms +0.84%
goto_definition 336.6±3.56µs 333.6±6.55µs -0.89%
highlight 8.7±0.16ms 9.0±0.10ms +3.45%
hover 486.9±6.36µs 491.4±9.63µs +0.92%
idents_at_position 119.6±0.94µs 119.3±0.69µs -0.25%
inlay_hints 622.4±12.63µs 638.0±12.26µs +2.51%
on_enter 2.0±0.03µs 1959.2±93.72ns -2.04%
parent_decl_at_position 3.6±0.04ms 3.7±0.03ms +2.78%
prepare_rename 330.0±8.91µs 337.5±6.36µs +2.27%
rename 9.0±0.25ms 9.3±0.10ms +3.33%
semantic_tokens 1177.4±35.40µs 1293.2±8.72µs +9.84%
token_at_position 328.9±3.14µs 331.1±2.02µs +0.67%
tokens_at_position 3.6±0.01ms 3.7±0.07ms +2.78%
tokens_for_file 398.0±4.50µs 401.5±3.39µs +0.88%
traverse 38.3±1.04ms 37.4±0.80ms -2.35%

@ironcev ironcev marked this pull request as ready for review August 7, 2024 22:18
@ironcev ironcev requested review from a team as code owners August 7, 2024 22:18
@ironcev ironcev enabled auto-merge (squash) August 7, 2024 22:19
@ironcev ironcev merged commit 589d3b9 into master Aug 8, 2024
40 checks passed
@ironcev ironcev deleted the ironcev/6332-inlining-functions-with-asm-blocks branch August 8, 2024 08:30
Copy link

github-actions bot commented Aug 8, 2024

Benchmark for dd8f829

Click to view benchmark
Test Base PR %
code_action 5.2±0.01ms 5.2±0.06ms 0.00%
code_lens 288.8±10.48ns 285.9±8.14ns -1.00%
compile 2.6±0.05s 2.6±0.05s 0.00%
completion 4.6±0.02ms 4.7±0.11ms +2.17%
did_change_with_caching 2.6±0.02s 2.6±0.02s 0.00%
document_symbol 849.9±20.36µs 926.0±23.19µs +8.95%
format 72.0±0.62ms 72.3±0.57ms +0.42%
goto_definition 340.2±6.43µs 340.2±6.68µs 0.00%
highlight 9.0±0.05ms 9.0±0.12ms 0.00%
hover 492.1±7.18µs 495.0±9.81µs +0.59%
idents_at_position 121.1±0.41µs 118.4±0.40µs -2.23%
inlay_hints 629.9±56.99µs 638.6±13.46µs +1.38%
on_enter 2.0±0.05µs 2.0±0.08µs 0.00%
parent_decl_at_position 3.6±0.01ms 3.7±0.05ms +2.78%
prepare_rename 338.2±7.61µs 337.3±5.60µs -0.27%
rename 9.3±0.18ms 9.3±0.05ms 0.00%
semantic_tokens 1270.3±15.23µs 1260.6±7.86µs -0.76%
token_at_position 334.4±1.68µs 335.4±2.77µs +0.30%
tokens_at_position 3.6±0.05ms 3.7±0.02ms +2.78%
tokens_for_file 398.3±3.71µs 398.2±1.76µs -0.03%
traverse 37.6±1.19ms 36.6±0.70ms -2.66%

esdrubal pushed a commit that referenced this pull request Aug 13, 2024
…er (#6404)

## Description

This PR fixes #6332 and #6354 by:
- including number of instructions in ASM blocks when calculating
overall number of instructions for function inlining.
- properly lowering ASM blocks that return unit, `()`, without return
register to returning `$zero` in the ASM.

Additionally, the PR:
- removes dead ASM blocks (that do not have side-effects) in the DCE
pass.
- prints ASM blocks that return `()` without a register as `-> ()` to
make it consistent with functions.
- emits a warning if an ASM block is empty.
- adds expressive diagnostic for `UninitializedAsmRegShadowsItem`
warning and extends the warning for constants and configurables.
- removes obsolete `NamespaceAttributeDeprecated` warning and its empty
tests.
- harmonizes and defines guidelines for ASM instruction comments.

Closes #6332.
Closes #6354.

## Bytecode size changes

Changes in the `fn-inline` and `dce` optimizations had a minimal impact
on the bytcode sizes of the `should_pass` test programs. Out of 455
tests, only 13 tests changed sizes. 8 tests got a size increase of 0.8%
in average, while 5 tests got size decrease of 3.0% in average.

The real-world
[compolabs-orderbook](https://github.com/compolabs/orderbook-contract)
contract got a minimal size decrease of 0.16%.

<details>
  <summary>Click here for the numbers</summary>

Test | Before | After | Decrease | Percentage
-- | -- | -- | -- | --
empty_fields_in_storage_struct | 28384 | 28456 | -72 | -0.25
language/deprecated_attribute | 224 | 208 | 16 | 7.14
language/duplicated_storage_keys | 224 | 208 | 16 | 7.14
language/references/dereferencing_operator_dot_on_structs | 124920 |
125272 | -352 | -0.28
language/references/dereferencing_operator_dot_on_tuples | 124920 |
125272 | -352 | -0.28
language/references/dereferencing_operator_index | 92376 | 92344 | 32 |
0.03
language/references/dereferencing_operator_star | 151152 | 151536 | -384
| -0.25
language/references/impl_reference_types | 7840 | 7776 | 64 | 0.81

language/references/reassigning_via_references_passed_and_returned_to_and_from_functions
| 39008 | 39184 | -176 | -0.45
language/references/reassigning_via_references_to_expressions | 36920 |
37064 | -144 | -0.39
language/references/reassigning_via_references_to_values | 13952 | 13936
| 16 | 0.11
stdlib/storage_vec_insert | 8480 | 8552 | -72 | -0.85
stdlib/vec_byte_remove | 1904 | 1976 | -72 | -3.78

</details>

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] 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.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
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: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: ir IRgen and sway-ir including optimization passes compiler: optimization IR Optimization Passes compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
3 participants