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

Use $one for true in ASM instead of using data section #6186

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

ironcev
Copy link
Member

@ironcev ironcev commented Jun 25, 2024

Description

This PR generates $one register access for the boolean constant true, instead of placing 1 into the data section.

This removes loading from the data section when using the constant.

E.g., when calling function(true), instead of:

.data:
data_0 .byte 1
load $r30 data_0                        ; literal instantiation
move $$arg0 $r30                        ; pass arg 0
mova $$reta .9                          ; set new return addr
fncall .4                               ; call function_1

we now have:

move $$arg0 $one                        ; pass arg 0
mova $$reta .9                          ; set new return addr
fncall .4                               ; call function_1

Out of 450 should_pass tests, 140 got decreased in the bytecode size.

Click here for the numbers
Test Before After Decrease Percentage
dca/trait_method_neq 408 392 16 3.92
empty_fields_in_storage_struct 28920 28912 8 0.03
forc/contract_dependencies/contract_b 1160 1152 8 0.69
forc/contract_dependencies/contract_c 1160 1152 8 0.69
language/aliased_imports 352 336 16 4.55
language/arg_demotion_inline 1360 1344 16 1.18
language/array_basics 792 784 8 1.01
language/array_generics 400 384 16 4.00
language/associated_const_trait_const 320 312 8 2.50
language/b256_bitwise_ops 6808 6800 8 0.12
language/basic_func_decl 320 312 8 2.50
language/basic_predicate 104 88 16 15.38
language/binary_and_hex_literals 320 312 8 2.50
language/bitwise_not 320 312 8 2.50
language/blanket_trait 320 312 8 2.50
language/bool_and_or 344 336 8 2.33
language/break_and_continue 896 888 8 0.89
language/configurable_consts 7216 7184 32 0.44
language/const_decl_in_library 344 336 8 2.33
language/contract_caller_as_ret 1160 1152 8 0.69
language/diagnose_unknown_annotations 1528 1512 16 1.05
language/diverging_exprs 1144 1112 32 2.80
language/enum_in_fn_decl 408 392 16 3.92
language/enum_instantiation 3752 3688 64 1.71
language/eq_and_neq 2072 2056 16 0.77
language/for_loops 4488 4472 16 0.36
language/funcs_with_generic_types 320 312 8 2.50
language/generic_functions 320 312 8 2.50
language/generic_impl_self 2616 2584 32 1.22
language/generic_result_method 680 656 24 3.53
language/generic_struct 336 328 8 2.38
language/generic_structs 608 584 24 3.95
language/generic_trait_constraints 1048 1040 8 0.76
language/generic_traits 1312 1304 8 0.61
language/generic_transpose 912 904 8 0.88
language/generic_tuple_trait 832 824 8 0.96
language/generic_type_inference 3352 3344 8 0.24
language/generic_where_in_impl_self2 504 496 8 1.59
language/generic_where_in_impl_self 504 496 8 1.59
language/import_with_different_callpaths 2752 2744 8 0.29
language/insert_element_reg_reuse 2488 2472 16 0.64
language/is_prime 1144 1112 32 2.80
language/is_reference_type 320 312 8 2.50
language/local_impl_for_ord 320 312 8 2.50
language/match_expressions_enums 3336 3320 16 0.48
language/match_expressions_explicit_rets 320 312 8 2.50
language/match_expressions_inside_generic_functions 520 512 8 1.54
language/match_expressions_or 9184 9176 8 0.09
language/match_expressions_simple 408 400 8 1.96
language/match_expressions_structs 408 400 8 1.96
language/match_expressions_unreachable_catch_all_last_arm 2296 2232 64 2.79
language/match_expressions_unreachable_catch_all_middle_arm 2088 2040 48 2.30
language/match_expressions_unreachable_last_arm 3032 2936 96 3.17
language/match_expressions_unreachable_middle_arm 3440 3336 104 3.02
language/match_expressions_with_self 464 456 8 1.72
language/modulo_uint_test 320 312 8 2.50
language/mutable_and_initd 432 424 8 1.85
language/nested_structs 1104 1088 16 1.45
language/nested_while_and_if 416 408 8 1.92
language/new_allocator_test 792 776 16 2.02
language/numeric_constants 320 312 8 2.50
language/ops 424 408 16 3.77
language/out_of_order_decl 328 320 8 2.44
language/predicate_while 128 120 8 6.25
language/predicate_while_dep 128 120 8 6.25
language/raw_identifiers 448 432 16 3.57
language/references/dereferencing_operator_dot_on_structs 125040 124888 152 0.12
language/references/dereferencing_operator_dot_on_tuples 125040 124888 152 0.12
language/references/dereferencing_operator_index 92368 92344 24 0.03
language/references/dereferencing_operator_star 151248 151120 128 0.08
language/references/passing_and_returning_references_to_and_from_functions 15928 15912 16 0.10
language/references/reassigning_via_references_passed_and_returned_to_and_from_functions 38904 38832 72 0.19
language/references/reassigning_via_references_to_expressions 39368 39304 64 0.16
language/references/reassigning_via_references_to_values 13976 13920 56 0.40
language/references/referencing_local_vars_and_values 36424 36376 48 0.13
language/ref_mutable_fn_args_bool 320 312 8 2.50
language/self_impl_reassignment 936 928 8 0.85
language/smo 1936 1912 24 1.24
language/smo_opcode 408 392 16 3.92
language/struct_destructuring 432 424 8 1.85
language/struct_instantiation 2296 2184 112 4.88
language/supertraits 6056 6048 8 0.13
language/supertraits_with_trait_methods 400 392 8 2.00
language/trait_method_ascription_disambiguate 440 424 16 3.64
language/trait_method_generic_qualified 440 424 16 3.64
language/trait_method_qualified 320 312 8 2.50
language/trait_nested 912 896 16 1.75
language/tuple_access 456 440 16 3.51
language/tuple_in_struct 656 640 16 2.44
language/tuple_trait 408 392 16 3.92
language/type_alias 3880 3856 24 0.62
language/typeinfo_custom_callpath2 272 264 8 2.94
language/typeinfo_custom_callpath 272 264 8 2.94
language/typeinfo_custom_callpath_with_import 288 280 8 2.78
language/unary_not_basic_2 320 312 8 2.50
language/unary_not_basic 320 312 8 2.50
language/valid_impurity 1104 1096 8 0.72
language/where_clause_functions 1984 1960 24 1.21
language/while_loops 584 568 16 2.74
static_analysis/cei_pattern_violation_more_complex_logic 16528 16520 8 0.05
static_analysis/cei_pattern_violation_smo_intrinsic 2248 2232 16 0.71
static_analysis/cei_pattern_violation_storage_map_and_vec 8000 7992 8 0.10
stdlib/address_test 4200 4184 16 0.38
stdlib/alloc_test 856 840 16 1.87
stdlib/assert_eq 6376 6368 8 0.13
stdlib/assert_ne 6096 6080 16 0.26
stdlib/assert_test 320 312 8 2.50
stdlib/b512_test 3384 3368 16 0.47
stdlib/block_height 368 352 16 4.35
stdlib/contract_id_test 656 640 16 2.44
stdlib/contract_id_type 648 640 8 1.23
stdlib/eq_custom_type 736 720 16 2.17
stdlib/identity_eq 2480 2472 8 0.32
stdlib/intrinsics 320 312 8 2.50
stdlib/iterator 2528 2512 16 0.63
stdlib/option 22872 22816 56 0.24
stdlib/option_eq 12240 12216 24 0.20
stdlib/raw_ptr 4520 4480 40 0.88
stdlib/raw_slice 1016 1008 8 0.79
stdlib/require 1160 1128 32 2.76
stdlib/result 8944 8896 48 0.54
stdlib/sha256 2208 2192 16 0.72
stdlib/storage_vec_insert 8320 8304 16 0.19
stdlib/u128_div_test 2752 2744 8 0.29
stdlib/u128_log_test 4560 4544 16 0.35
stdlib/u128_mul_test 1488 1480 8 0.54
stdlib/u128_root_test 4360 4344 16 0.37
stdlib/u128_test 6488 6480 8 0.12
stdlib/vec 107152 107088 64 0.06
stdlib/vec_swap 23824 23808 16 0.07
storage_into 1784 1768 16 0.90
supertraits_for_abis_ownable 7336 7328 8 0.11
test_contracts/abi_with_tuples_contract 2584 2568 16 0.62
test_contracts/basic_storage 34672 34648 24 0.07
test_contracts/storage_enum_contract 18312 18272 40 0.22
test_contracts/storage_namespace 32976 32952 24 0.07
unit_tests/predicate_multi_test 304 288 16 5.26
unit_tests/predicate_with_nested_libs 632 624 8 1.27
unit_tests/script_multi_test 896 880 16 1.79
unit_tests/workspace_test 896 880 16 1.79

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: codegen Everything to do with IR->ASM, register allocation, etc. labels Jun 25, 2024
@ironcev ironcev self-assigned this Jun 25, 2024
Copy link

Benchmark for 328497c

Click to view benchmark
Test Base PR %
code_action 5.0±0.01ms 5.1±0.02ms +2.00%
code_lens 308.0±8.33ns 306.4±8.50ns -0.52%
compile 3.4±0.07s 3.5±0.06s +2.94%
completion 4.6±0.11ms 4.6±0.31ms 0.00%
did_change_with_caching 3.2±0.07s 3.2±0.07s 0.00%
document_symbol 856.9±15.46µs 915.8±25.46µs +6.87%
format 87.7±1.27ms 87.5±1.19ms -0.23%
goto_definition 340.3±5.77µs 345.3±8.61µs +1.47%
highlight 8.6±0.16ms 8.6±0.04ms 0.00%
hover 563.7±4.62µs 572.2±7.12µs +1.51%
idents_at_position 119.3±0.41µs 119.8±0.48µs +0.42%
inlay_hints 676.9±10.52µs 636.0±21.83µs -6.04%
on_enter 475.7±32.83ns 467.0±17.60ns -1.83%
parent_decl_at_position 3.5±0.06ms 3.5±0.01ms 0.00%
prepare_rename 339.3±7.82µs 344.8±7.19µs +1.62%
rename 8.9±0.10ms 8.9±0.20ms 0.00%
semantic_tokens 1212.4±6.45µs 1290.1±70.79µs +6.41%
token_at_position 330.6±2.59µs 331.7±4.31µs +0.33%
tokens_at_position 3.5±0.02ms 3.5±0.04ms 0.00%
tokens_for_file 396.8±4.64µs 401.2±3.02µs +1.11%
traverse 37.5±0.82ms 37.4±0.75ms -0.27%

@ironcev ironcev marked this pull request as ready for review June 25, 2024 21:54
@ironcev ironcev requested a review from a team as a code owner June 25, 2024 21:54
@ironcev ironcev requested a review from a team June 25, 2024 21:55
@ironcev ironcev enabled auto-merge (squash) June 25, 2024 21:56
Copy link

Benchmark for ac87de3

Click to view benchmark
Test Base PR %
code_action 5.0±0.06ms 5.1±0.17ms +2.00%
code_lens 314.2±10.65ns 314.7±17.62ns +0.16%
compile 2.6±0.04s 2.6±0.01s 0.00%
completion 4.5±0.03ms 4.5±0.08ms 0.00%
did_change_with_caching 2.5±0.02s 2.5±0.02s 0.00%
document_symbol 910.0±43.89µs 913.4±33.19µs +0.37%
format 86.7±1.46ms 88.5±1.56ms +2.08%
goto_definition 337.2±7.35µs 339.4±7.72µs +0.65%
highlight 8.7±0.47ms 8.7±0.09ms 0.00%
hover 491.2±3.43µs 491.6±9.34µs +0.08%
idents_at_position 120.1±0.27µs 120.0±0.78µs -0.08%
inlay_hints 624.6±21.57µs 634.6±26.81µs +1.60%
on_enter 466.9±9.06ns 478.5±17.26ns +2.48%
parent_decl_at_position 3.6±0.02ms 3.6±0.10ms 0.00%
prepare_rename 338.8±6.62µs 340.3±10.37µs +0.44%
rename 8.9±0.02ms 9.0±0.17ms +1.12%
semantic_tokens 1260.7±11.78µs 1244.6±13.11µs -1.28%
token_at_position 331.7±2.98µs 334.2±2.97µs +0.75%
tokens_at_position 3.5±0.04ms 3.6±0.19ms +2.86%
tokens_for_file 397.0±7.46µs 404.4±4.40µs +1.86%
traverse 38.1±0.80ms 38.4±0.50ms +0.79%

@ironcev ironcev merged commit 741373b into master Jun 26, 2024
38 checks passed
@ironcev ironcev deleted the ironcev/use-one-register-for-true-constant branch June 26, 2024 13:02
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.

3 participants