Skip to content

Conversation

vaivaswatha
Copy link
Contributor

Copy link
Member

@ironcev ironcev left a comment

Choose a reason for hiding this comment

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

What if the returned unit value is actually used? Please see my remark in this comment.

Copy link

codspeed-hq bot commented Sep 22, 2025

CodSpeed Performance Report

Merging #7401 will not alter performance

Comparing vaivaswatha/unit_ret_skip (30bc3da) with master (ec6f0ca)

Summary

✅ 25 untouched

Copy link
Member

@ironcev ironcev left a comment

Choose a reason for hiding this comment

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

To the returned unit value being used, we had an ICE before in case of asm blocks that were returning unit, where the return register was not set. The issue was fixed in #6404.

@vaivaswatha
Copy link
Contributor Author

What if the returned unit value is actually used? Please see my remark in this comment.

I think a solution to handle this would be:

  1. A function returning unit will just skip assigning to retv
  2. In the caller, if the callee returns unit, then we just set the returned value to zero instead of what is returned by the function. Then that mov will be DCE'd if it isn't used.

What do you think?

@ironcev
Copy link
Member

ironcev commented Sep 22, 2025

Yes makes sense. We are free to define the calling conventions. It is cheaper then analyzing if there are callers that use the returned value.

@vaivaswatha
Copy link
Contributor Author

Size changes on our `should_pass` tests:
Test Before After
should_pass/language/abi_cast_nested_method [2.328 KB] [2.304 KB]
should_pass/language/abort_control_flow_good [328 B] [328 B]
should_pass/language/addrof_intrinsic [3.144 KB] [3.144 KB]
should_pass/language/aliased_imports [344 B] [344 B]
should_pass/language/arg_demotion_inline [1.072 KB] [1.064 KB]
should_pass/language/args_on_stack [18.256 KB] [18.248 KB]
should_pass/language/array/array_basics [648 B] [648 B]
should_pass/language/array/array_generics [344 B] [344 B]
should_pass/language/asm/instructions/bldd [32 B] [32 B]
should_pass/language/asm/instructions/ecall [32 B] [32 B]
should_pass/language/asm/instructions/ldc [88 B] [88 B]
should_pass/language/asm/instructions/wqxx [2.2 KB] [2.184 KB]
should_pass/language/asm_empty_block [32 B] [32 B]
should_pass/language/asm_expr_basic [456 B] [456 B]
should_pass/language/asm_uninitialized_register_shadows_item [376 B] [368 B]
should_pass/language/asm_without_return [32 B] [32 B]
should_pass/language/associated_const_abi [4.816 KB] [4.8 KB]
should_pass/language/associated_const_abi_multiple [3.216 KB] [3.2 KB]
should_pass/language/associated_const_impl [344 B] [344 B]
should_pass/language/associated_const_impl_local_same_name [344 B] [344 B]
should_pass/language/associated_const_impl_multiple [112 B] [104 B]
should_pass/language/associated_const_impl_self [472 B] [472 B]
should_pass/language/associated_const_in_decls_of_other_constants [2.384 KB] [2.368 KB]
should_pass/language/associated_const_trait [40 B] [40 B]
should_pass/language/associated_const_trait_default [112 B] [104 B]
should_pass/language/associated_const_trait_impl_method [344 B] [344 B]
should_pass/language/associated_const_trait_method [344 B] [344 B]
should_pass/language/associated_const_visibility [32 B] [32 B]
should_pass/language/associated_type_and_associated_const [344 B] [344 B]
should_pass/language/associated_type_ascription [344 B] [344 B]
should_pass/language/associated_type_container [1.504 KB] [1.488 KB]
should_pass/language/associated_type_container_in_library [1.504 KB] [1.488 KB]
should_pass/language/associated_type_fully_qualified [520 B] [504 B]
should_pass/language/associated_type_iterator [1.56 KB] [1.536 KB]
should_pass/language/associated_type_method [344 B] [344 B]
should_pass/language/associated_type_parameter [344 B] [344 B]
should_pass/language/attributes_abi_name [1.424 KB] [1.416 KB]
should_pass/language/attributes_all_in_one [904 B] [896 B]
should_pass/language/attributes_test_attribute [32 B] [32 B]
should_pass/language/b256_bad_jumps [328 B] [328 B]
should_pass/language/b256_bitwise_ops [6.544 KB] [6.528 KB]
should_pass/language/b256_ops [2.488 KB] [2.456 KB]
should_pass/language/basic_func_decl [320 B] [320 B]
should_pass/language/basic_predicate [64 B] [64 B]
should_pass/language/binary_and_hex_literals [320 B] [320 B]
should_pass/language/binop_intrinsics [336 B] [336 B]
should_pass/language/bitwise_not [320 B] [320 B]
should_pass/language/blanket_trait [320 B] [320 B]
should_pass/language/bool_and_or [336 B] [336 B]
should_pass/language/break_and_continue [808 B] [808 B]
should_pass/language/break_and_continue_block_ret [32 B] [32 B]
should_pass/language/builtin_type_method_call [336 B] [336 B]
should_pass/language/callpath_local_shadowing [104 B] [96 B]
should_pass/language/chained_if_let [464 B] [464 B]
should_pass/language/complex_ir_cfg [832 B] [824 B]
should_pass/language/configurable_consts [5 KB] [4.92 KB]
should_pass/language/configurable_tests [4.984 KB] [4.904 KB]
should_pass/language/const_decl_and_use_in_library [336 B] [336 B]
should_pass/language/const_decl_in_library [360 B] [360 B]
should_pass/language/const_generics [904 B] [896 B]
should_pass/language/const_indexing_aggregates_asmgen [568 B] [568 B]
should_pass/language/const_inits [2.104 KB] [2.104 KB]
should_pass/language/contract_caller_as_ret [888 B] [888 B]
should_pass/language/contract_caller_dynamic_address [1.744 KB] [1.728 KB]
should_pass/language/contract_calls_unwrapped_contract_id [1.808 KB] [1.792 KB]
should_pass/language/contract_ret_intrinsic [3.184 KB] [3.168 KB]
should_pass/language/dereferenced_projection_reassignment [1.624 KB] [1.616 KB]
should_pass/language/diverging_exprs [832 B] [824 B]
should_pass/language/doc_comments [928 B] [928 B]
should_pass/language/dummy_method_issue [288 B] [280 B]
should_pass/language/duplicated_storage_keys [240 B] [240 B]
should_pass/language/empty_method_initializer [744 B] [744 B]
should_pass/language/enum_destructuring [400 B] [400 B]
should_pass/language/enum_if_let [728 B] [728 B]
should_pass/language/enum_if_let_large_type [648 B] [648 B]
should_pass/language/enum_in_fn_decl [416 B] [416 B]
should_pass/language/enum_init_fn_call [584 B] [584 B]
should_pass/language/enum_instantiation [3.392 KB] [3.376 KB]
should_pass/language/enum_padding [1.64 KB] [1.624 KB]
should_pass/language/enum_type_inference [336 B] [336 B]
should_pass/language/enum_variant_imports [456 B] [456 B]
should_pass/language/eq_and_neq [1.416 KB] [1.408 KB]
should_pass/language/eq_intrinsic [336 B] [336 B]
should_pass/language/fallback_only [1.912 KB] [1.904 KB]
should_pass/language/far_jumps/many_blobs [7.44048 MB] [7.44048 MB]
should_pass/language/far_jumps/single_blob [336 B] [336 B]
should_pass/language/for_loops [3.08 KB] [3.056 KB]
should_pass/language/fqp_in_lib [104 B] [96 B]
should_pass/language/funcs_with_generic_types [320 B] [320 B]
should_pass/language/function_return_type_unification [352 B] [352 B]
should_pass/language/generic_functions [320 B] [320 B]
should_pass/language/generic_impl_self [3.176 KB] [3.168 KB]
should_pass/language/generic_impl_self_where [1.712 KB] [1.712 KB]
should_pass/language/generic_inside_generic [432 B] [432 B]
should_pass/language/generic_result_method [624 B] [616 B]
should_pass/language/generic_struct [320 B] [320 B]
should_pass/language/generic_struct_instantiation [328 B] [328 B]
should_pass/language/generic_structs [320 B] [320 B]
should_pass/language/generic_trait_constraints [816 B] [800 B]
should_pass/language/generic_traits [1.232 KB] [1.232 KB]
should_pass/language/generic_transpose [856 B] [856 B]
should_pass/language/generic_tuple_trait [504 B] [504 B]
should_pass/language/generic_type_inference [2.512 KB] [2.472 KB]
should_pass/language/generic_where_in_impl_self [456 B] [456 B]
should_pass/language/generic_where_in_impl_self2 [456 B] [456 B]
should_pass/language/generics_in_contract [2.352 KB] [2.336 KB]
should_pass/language/gtf_intrinsic [752 B] [752 B]
should_pass/language/if_elseif_enum [688 B] [680 B]
should_pass/language/if_implicit_unit [104 B] [96 B]
should_pass/language/if_let_no_side_effects [440 B] [440 B]
should_pass/language/impl_self_method [352 B] [352 B]
should_pass/language/impl_self_method_order [352 B] [352 B]
should_pass/language/implicit_casting [336 B] [336 B]
should_pass/language/implicit_return [336 B] [336 B]
should_pass/language/import_from_private_ancestor [32 B] [32 B]
should_pass/language/import_method_from_other_file [416 B] [416 B]
should_pass/language/import_star_name_clash [1.712 KB] [1.712 KB]
should_pass/language/import_trailing_comma [344 B] [344 B]
should_pass/language/import_with_different_callpaths [1.512 KB] [1.496 KB]
should_pass/language/impure_ifs [944 B] [944 B]
should_pass/language/inline_if_expr_const [104 B] [96 B]
should_pass/language/insert_element_reg_reuse [1.952 KB] [1.936 KB]
should_pass/language/integer_type_inference [944 B] [936 B]
should_pass/language/intrinsics/dbg [2.496 KB] [2.48 KB]
should_pass/language/intrinsics/dbg_release [5.672 KB] [5.64 KB]
should_pass/language/intrinsics/transmute [1.616 KB] [1.608 KB]
should_pass/language/is_prime [904 B] [904 B]
should_pass/language/is_reference_type [320 B] [320 B]
should_pass/language/largeint_sroa [544 B] [536 B]
should_pass/language/left_to_right_func_args_evaluation [368 B] [368 B]
should_pass/language/local_impl_for_ord [320 B] [320 B]
should_pass/language/logging [2.952 KB] [2.928 KB]
should_pass/language/main_args/main_args_empty [336 B] [336 B]
should_pass/language/main_args/main_args_empty [48 B] [48 B]
should_pass/language/main_args/main_args_generics [1.312 KB] [1.304 KB]
should_pass/language/main_args/main_args_one_u64 [408 B] [408 B]
should_pass/language/main_args/main_args_ref [424 B] [424 B]
should_pass/language/main_args/main_args_ref_copy [464 B] [464 B]
should_pass/language/main_args/main_args_ref_ref [544 B] [536 B]
should_pass/language/main_args/main_args_two_u64 [440 B] [440 B]
should_pass/language/main_args/main_args_various_types [2.296 KB] [2.272 KB]
should_pass/language/main_returns_unit [104 B] [96 B]
should_pass/language/many_stack_variables [376 B] [376 B]
should_pass/language/marker_traits/marker_trait_enum_implemented_for_all_enums [32 B] [32 B]
should_pass/language/marker_traits/marker_trait_error_implemented_for_error_types [32 B] [32 B]
should_pass/language/match_expressions_all [1.608 KB] [1.6 KB]
should_pass/language/match_expressions_constants [3.016 KB] [3.016 KB]
should_pass/language/match_expressions_empty_enums [336 B] [336 B]
should_pass/language/match_expressions_enums [2.696 KB] [2.696 KB]
should_pass/language/match_expressions_explicit_rets [320 B] [320 B]
should_pass/language/match_expressions_inside_generic_functions [488 B] [488 B]
should_pass/language/match_expressions_mismatched [392 B] [392 B]
should_pass/language/match_expressions_nested [1.608 KB] [1.608 KB]
should_pass/language/match_expressions_rest [1.504 KB] [1.504 KB]
should_pass/language/match_expressions_simple [400 B] [400 B]
should_pass/language/match_expressions_structs [392 B] [392 B]
should_pass/language/match_expressions_unreachable_catch_all_last_arm [1.088 KB] [1.08 KB]
should_pass/language/match_expressions_unreachable_catch_all_middle_arm [904 B] [896 B]
should_pass/language/match_expressions_unreachable_last_arm [2.256 KB] [2.248 KB]
should_pass/language/match_expressions_unreachable_middle_arm [2.6 KB] [2.592 KB]
should_pass/language/match_expressions_with_self [480 B] [480 B]
should_pass/language/mega_example [8.288 KB] [8.248 KB]
should_pass/language/memcpy [680 B] [672 B]
should_pass/language/method_indirect_inference [640 B] [640 B]
should_pass/language/method_nested_type_args [104 B] [96 B]
should_pass/language/method_on_empty_struct [328 B] [328 B]
should_pass/language/method_on_primitives [240 B] [240 B]
should_pass/language/method_unambiguous [584 B] [584 B]
should_pass/language/module_dep [32 B] [32 B]
should_pass/language/module_dep_multiple [32 B] [32 B]
should_pass/language/module_dep_self [32 B] [32 B]
should_pass/language/modulo_uint_test [320 B] [320 B]
should_pass/language/multi_impl_self [336 B] [336 B]
should_pass/language/multi_item_import [320 B] [320 B]
should_pass/language/mutable_and_initd [448 B] [448 B]
should_pass/language/mutable_arrays [336 B] [336 B]
should_pass/language/mutable_arrays_enum [400 B] [400 B]
should_pass/language/mutable_arrays_multiple_nested [328 B] [328 B]
should_pass/language/mutable_arrays_nested [328 B] [328 B]
should_pass/language/mutable_arrays_struct [336 B] [336 B]
should_pass/language/mutable_arrays_swap [336 B] [336 B]
should_pass/language/name_resolution_after_monomorphization [368 B] [368 B]
should_pass/language/nested_generics [320 B] [320 B]
should_pass/language/nested_struct_destructuring [328 B] [328 B]
should_pass/language/nested_structs [1.112 KB] [1.112 KB]
should_pass/language/nested_while_and_if [432 B] [432 B]
should_pass/language/new_allocator_test [408 B] [408 B]
should_pass/language/non_literal_const_decl [336 B] [336 B]
should_pass/language/numeric_constants [432 B] [424 B]
should_pass/language/numeric_type_propagation [432 B] [424 B]
should_pass/language/op_precedence [320 B] [320 B]
should_pass/language/ops [416 B] [416 B]
should_pass/language/out_of_order_decl [320 B] [320 B]
should_pass/language/overlapped_trait_impls [672 B] [672 B]
should_pass/language/panic_expression/panic_keyword_behind_feature_flag_on [32 B] [32 B]
should_pass/language/panic_expression/panic_string_slices [176 B] [176 B]
should_pass/language/panic_expression/panicking_predicate [72 B] [72 B]
should_pass/language/predicate_while [112 B] [112 B]
should_pass/language/predicate_while_dep [112 B] [112 B]
should_pass/language/prelude_access [104 B] [96 B]
should_pass/language/prelude_access2 [104 B] [96 B]
should_pass/language/primitive_type_argument [336 B] [336 B]
should_pass/language/pusha_popa_multiple_defreg [2.048 KB] [2.032 KB]
should_pass/language/raw_identifiers [3.528 KB] [3.504 KB]
should_pass/language/raw_identifiers [3.528 KB] [3.504 KB]
should_pass/language/raw_ptr/vec_ret [904 B] [896 B]
should_pass/language/reassignment_operators [328 B] [328 B]
should_pass/language/reassignment_rhs_lhs_evaluation_order [840 B] [840 B]
should_pass/language/redundant_return [328 B] [328 B]
should_pass/language/reexport/aliases [1.104 KB] [1.104 KB]
should_pass/language/reexport/multiple_imports_of_same_reexport [1.528 KB] [1.528 KB]
should_pass/language/reexport/reexport_paths [1 KB] [992 B]
should_pass/language/reexport/reexport_paths_external_lib [2.184 KB] [2.184 KB]
should_pass/language/reexport/shadowing_in_reexporting_module [1.536 KB] [1.536 KB]
should_pass/language/reexport/simple_glob_import [904 B] [904 B]
should_pass/language/reexport/simple_item_import [904 B] [904 B]
should_pass/language/reexport/visibility [904 B] [904 B]
should_pass/language/ref_mutable_arrays [336 B] [336 B]
should_pass/language/ref_mutable_arrays_inline [336 B] [336 B]
should_pass/language/ref_mutable_fn_args_bool [320 B] [320 B]
should_pass/language/ref_mutable_fn_args_call [336 B] [336 B]
should_pass/language/ref_mutable_fn_args_struct [336 B] [336 B]
should_pass/language/ref_mutable_fn_args_struct_assign [336 B] [336 B]
should_pass/language/ref_mutable_fn_args_u32 [352 B] [352 B]
should_pass/language/references/dereferencing_control_flow_expressions [744 B] [744 B]
should_pass/language/references/impl_reference_types [13.568 KB] [13.568 KB]
should_pass/language/references/mutability_of_references [896 B] [896 B]
should_pass/language/references/mutability_of_references_memcpy_bug [2.984 KB] [2.952 KB]
should_pass/language/references/reassigning_via_references_in_aggregates [4.616 KB] [4.544 KB]
should_pass/language/references/references_and_type_aliases [648 B] [648 B]
should_pass/language/references/references_in_aggregates [3.824 KB] [3.784 KB]
should_pass/language/references/references_in_asm_blocks [1.896 KB] [1.872 KB]
should_pass/language/references/referencing_control_flow_expressions [504 B] [504 B]
should_pass/language/references/referencing_function_parameters [3.72 KB] [3.648 KB]
should_pass/language/references/referencing_function_parameters_simple [1.6 KB] [1.576 KB]
should_pass/language/references/referencing_global_constants [1.216 KB] [1.216 KB]
should_pass/language/references/referencing_parts_of_aggregates [4.28 KB] [4.208 KB]
should_pass/language/references/referencing_references [1.032 KB] [1.024 KB]
should_pass/language/references/type_unification_of_references [3.056 KB] [3.056 KB]
should_pass/language/ret_small_string [416 B] [416 B]
should_pass/language/ret_string_in_struct [480 B] [472 B]
should_pass/language/retd_b256 [464 B] [456 B]
should_pass/language/retd_small_array [480 B] [480 B]
should_pass/language/retd_struct [912 B] [904 B]
should_pass/language/retd_zero_len_array [216 B] [208 B]
should_pass/language/revert_in_first_if_branch [104 B] [104 B]
should_pass/language/same_const_name [104 B] [96 B]
should_pass/language/same_const_name_lib [32 B] [32 B]
should_pass/language/self_impl_reassignment [896 B] [888 B]
should_pass/language/shadowing/shadowed_glob_imports [480 B] [472 B]
should_pass/language/shadowing/shadowed_prelude_imports [352 B] [352 B]
should_pass/language/size_of [328 B] [328 B]
should_pass/language/slice/slice_contract [2.72 KB] [2.696 KB]
should_pass/language/slice/slice_intrinsics [7.184 KB] [7.152 KB]
should_pass/language/slice/slice_script [568 B] [568 B]
should_pass/language/smo [1.888 KB] [1.88 KB]
should_pass/language/smo_opcode [376 B] [376 B]
should_pass/language/string_slice/string_slice_contract [2.688 KB] [2.664 KB]
should_pass/language/string_slice/string_slice_features [408 B] [408 B]
should_pass/language/string_slice/string_slice_script [640 B] [640 B]
should_pass/language/struct_destructuring [336 B] [336 B]
should_pass/language/struct_field_access [336 B] [336 B]
should_pass/language/struct_field_reassignment [328 B] [328 B]
should_pass/language/struct_init_reorder [184 B] [176 B]
should_pass/language/struct_instantiation [1.928 KB] [1.92 KB]
should_pass/language/submodule_visibility [32 B] [32 B]
should_pass/language/supertraits [4.008 KB] [4.008 KB]
should_pass/language/supertraits_with_trait_methods [384 B] [384 B]
should_pass/language/totalord [2.368 KB] [2.328 KB]
should_pass/language/trait_constraint_param_order [320 B] [320 B]
should_pass/language/trait_generic_override [320 B] [320 B]
should_pass/language/trait_import_with_star [104 B] [96 B]
should_pass/language/trait_inference [760 B] [752 B]
should_pass/language/trait_method_ascription_disambiguate [320 B] [320 B]
should_pass/language/trait_method_generic_qualified [320 B] [320 B]
should_pass/language/trait_method_qualified [320 B] [320 B]
should_pass/language/trait_nested [840 B] [824 B]
should_pass/language/tuple_access [448 B] [448 B]
should_pass/language/tuple_desugaring [384 B] [384 B]
should_pass/language/tuple_field_reassignment [440 B] [440 B]
should_pass/language/tuple_in_struct [664 B] [664 B]
should_pass/language/tuple_indexing [344 B] [344 B]
should_pass/language/tuple_single_element [384 B] [384 B]
should_pass/language/tuple_trait [392 B] [392 B]
should_pass/language/tuple_types [352 B] [352 B]
should_pass/language/type_alias [2.488 KB] [2.48 KB]
should_pass/language/type_alias_from_dependency [32 B] [32 B]
should_pass/language/type_inference_propagation_of_type_constraints [736 B] [736 B]
should_pass/language/typeinfo_custom_callpath [160 B] [160 B]
should_pass/language/typeinfo_custom_callpath2 [160 B] [160 B]
should_pass/language/typeinfo_custom_callpath_with_import [176 B] [168 B]
should_pass/language/u256/u256_abi [744 B] [728 B]
should_pass/language/u256/u256_operators [3.92 KB] [3.912 KB]
should_pass/language/unary_not_basic [320 B] [320 B]
should_pass/language/unary_not_basic_2 [320 B] [320 B]
should_pass/language/unify_never [336 B] [336 B]
should_pass/language/unit_type_variants [664 B] [656 B]
should_pass/language/use_absolute_path [328 B] [328 B]
should_pass/language/use_full_path_names [344 B] [344 B]
should_pass/language/valid_impurity [888 B] [888 B]
should_pass/language/where_clause_enums [768 B] [768 B]
should_pass/language/where_clause_functions [1.848 KB] [1.848 KB]
should_pass/language/where_clause_generic_traits [104 B] [96 B]
should_pass/language/where_clause_generic_tuple [336 B] [336 B]
should_pass/language/where_clause_impls [424 B] [424 B]
should_pass/language/where_clause_methods [1.832 KB] [1.832 KB]
should_pass/language/where_clause_structs [616 B] [616 B]
should_pass/language/where_clause_traits [320 B] [320 B]
should_pass/language/while_loops [592 B] [592 B]
should_pass/language/zero_field_types [336 B] [336 B]
should_pass/language/zk_opcodes [456 B] [456 B]

@vaivaswatha vaivaswatha marked this pull request as ready for review September 23, 2025 06:33
@vaivaswatha vaivaswatha requested review from a team as code owners September 23, 2025 06:33
@vaivaswatha vaivaswatha requested a review from ironcev September 23, 2025 07:43
Copy link
Member

@ironcev ironcev left a comment

Choose a reason for hiding this comment

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

Great to see all those reductions in code size and gas usage in tests 😄 💪

@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 Sep 23, 2025
@vaivaswatha vaivaswatha requested review from ironcev and a team September 23, 2025 10:09
@vaivaswatha vaivaswatha enabled auto-merge (squash) September 23, 2025 10:23
@ironcev ironcev requested a review from a team September 23, 2025 11:33
@vaivaswatha vaivaswatha merged commit 36d2b12 into master Sep 24, 2025
45 checks passed
@vaivaswatha vaivaswatha deleted the vaivaswatha/unit_ret_skip branch September 24, 2025 02:22
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.

4 participants