Skip to content

Conversation

vaivaswatha
Copy link
Contributor

@vaivaswatha vaivaswatha commented Sep 11, 2025

This aids optimizations to perform better. For example https://github.com/IGI-111/blackjack comes down from 22.288 KB to 21.312 KB.

@vaivaswatha
Copy link
Contributor Author

vaivaswatha commented Sep 17, 2025

Code size impact on "should_pass" tests.
Test Before After
should_pass/language/abi_cast_nested_method [2.44 KB] [2.328 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.088 KB] [1.072 KB]
should_pass/language/args_on_stack [18.256 KB] [18.256 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.232 KB] [2.2 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] [376 B]
should_pass/language/asm_without_return [32 B] [32 B]
should_pass/language/associated_const_abi [5.04 KB] [4.816 KB]
should_pass/language/associated_const_abi_multiple [3.344 KB] [3.216 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] [112 B]
should_pass/language/associated_const_impl_self [472 B] [472 B]
should_pass/language/associated_const_in_decls_of_other_constants [2.464 KB] [2.384 KB]
should_pass/language/associated_const_trait [40 B] [40 B]
should_pass/language/associated_const_trait_default [112 B] [112 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.56 KB] [1.504 KB]
should_pass/language/associated_type_container_in_library [1.56 KB] [1.504 KB]
should_pass/language/associated_type_fully_qualified [544 B] [520 B]
should_pass/language/associated_type_iterator [1.616 KB] [1.56 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.456 KB] [1.424 KB]
should_pass/language/attributes_all_in_one [904 B] [904 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.544 KB]
should_pass/language/b256_ops [2.64 KB] [2.488 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] [104 B]
should_pass/language/chained_if_let [464 B] [464 B]
should_pass/language/complex_ir_cfg [856 B] [832 B]
should_pass/language/configurable_consts [5.088 KB] [5 KB]
should_pass/language/configurable_tests [5.072 KB] [4.984 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] [904 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.832 KB] [1.744 KB]
should_pass/language/contract_calls_unwrapped_contract_id [1.872 KB] [1.808 KB]
should_pass/language/contract_ret_intrinsic [3.304 KB] [3.184 KB]
should_pass/language/dereferenced_projection_reassignment [1.792 KB] [1.624 KB]
should_pass/language/diverging_exprs [832 B] [832 B]
should_pass/language/doc_comments [928 B] [928 B]
should_pass/language/dummy_method_issue [288 B] [288 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.424 KB] [3.392 KB]
should_pass/language/enum_padding [1.72 KB] [1.64 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.504 KB] [1.416 KB]
should_pass/language/eq_intrinsic [336 B] [336 B]
should_pass/language/fallback_only [1.944 KB] [1.912 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.152 KB] [3.08 KB]
should_pass/language/fqp_in_lib [104 B] [104 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.208 KB] [3.176 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] [624 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 [848 B] [816 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.608 KB] [2.512 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.376 KB] [2.352 KB]
should_pass/language/gtf_intrinsic [752 B] [752 B]
should_pass/language/if_elseif_enum [688 B] [688 B]
should_pass/language/if_implicit_unit [104 B] [104 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.544 KB] [1.512 KB]
should_pass/language/impure_ifs [944 B] [944 B]
should_pass/language/inline_if_expr_const [104 B] [104 B]
should_pass/language/insert_element_reg_reuse [2.016 KB] [1.952 KB]
should_pass/language/integer_type_inference [1.024 KB] [944 B]
should_pass/language/intrinsics/dbg [2.512 KB] [2.496 KB]
should_pass/language/intrinsics/dbg_release [5.696 KB] [5.672 KB]
should_pass/language/intrinsics/transmute [1.616 KB] [1.616 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] [544 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 [3.104 KB] [2.952 KB]
should_pass/language/main_args/main_args_empty [48 B] [48 B]
should_pass/language/main_args/main_args_generics [1.32 KB] [1.312 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 [560 B] [544 B]
should_pass/language/main_args/main_args_two_u64 [440 B] [440 B]
should_pass/language/main_args/main_args_various_types [2.392 KB] [2.296 KB]
should_pass/language/main_returns_unit [104 B] [104 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.608 KB]
should_pass/language/match_expressions_constants [3.264 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.336 KB] [1.088 KB]
should_pass/language/match_expressions_unreachable_catch_all_middle_arm [1.088 KB] [904 B]
should_pass/language/match_expressions_unreachable_last_arm [2.472 KB] [2.256 KB]
should_pass/language/match_expressions_unreachable_middle_arm [2.816 KB] [2.6 KB]
should_pass/language/match_expressions_with_self [480 B] [480 B]
should_pass/language/mega_example [8.816 KB] [8.288 KB]
should_pass/language/memcpy [680 B] [680 B]
should_pass/language/method_indirect_inference [640 B] [640 B]
should_pass/language/method_nested_type_args [104 B] [104 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 [448 B] [432 B]
should_pass/language/numeric_type_propagation [448 B] [432 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] [104 B]
should_pass/language/prelude_access2 [104 B] [104 B]
should_pass/language/primitive_type_argument [336 B] [336 B]
should_pass/language/pusha_popa_multiple_defreg [2.112 KB] [2.048 KB]
should_pass/language/raw_identifiers [3.64 KB] [3.528 KB]
should_pass/language/raw_ptr/vec_ret [928 B] [904 B]
should_pass/language/reassignment_operators [328 B] [328 B]
should_pass/language/reassignment_rhs_lhs_evaluation_order [896 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.016 KB] [1 KB]
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 [784 B] [744 B]
should_pass/language/references/impl_reference_types [15.968 KB] [13.568 KB]
should_pass/language/references/mutability_of_references [896 B] [896 B]
should_pass/language/references/mutability_of_references_memcpy_bug [3.192 KB] [2.984 KB]
should_pass/language/references/reassigning_via_references_in_aggregates [4.656 KB] [4.616 KB]
should_pass/language/references/references_and_type_aliases [648 B] [648 B]
should_pass/language/references/references_in_aggregates [3.824 KB] [3.824 KB]
should_pass/language/references/references_in_asm_blocks [1.896 KB] [1.896 KB]
should_pass/language/references/referencing_control_flow_expressions [504 B] [504 B]
should_pass/language/references/referencing_function_parameters [3.72 KB] [3.72 KB]
should_pass/language/references/referencing_function_parameters_simple [1.64 KB] [1.6 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.28 KB]
should_pass/language/references/referencing_references [1.032 KB] [1.032 KB]
should_pass/language/references/type_unification_of_references [3.056 KB] [3.056 KB]
should_pass/language/ret_small_string [432 B] [416 B]
should_pass/language/ret_string_in_struct [488 B] [480 B]
should_pass/language/retd_b256 [472 B] [464 B]
should_pass/language/retd_small_array [496 B] [480 B]
should_pass/language/retd_struct [920 B] [912 B]
should_pass/language/retd_zero_len_array [216 B] [216 B]
should_pass/language/revert_in_first_if_branch [104 B] [104 B]
should_pass/language/same_const_name [104 B] [104 B]
should_pass/language/same_const_name_lib [32 B] [32 B]
should_pass/language/self_impl_reassignment [896 B] [896 B]
should_pass/language/shadowing/shadowed_glob_imports [480 B] [480 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.848 KB] [2.72 KB]
should_pass/language/slice/slice_intrinsics [7.632 KB] [7.184 KB]
should_pass/language/slice/slice_script [584 B] [568 B]
should_pass/language/smo [1.936 KB] [1.888 KB]
should_pass/language/smo_opcode [376 B] [376 B]
should_pass/language/string_slice/string_slice_contract [2.816 KB] [2.688 KB]
should_pass/language/string_slice/string_slice_features [408 B] [408 B]
should_pass/language/string_slice/string_slice_script [656 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] [184 B]
should_pass/language/struct_instantiation [1.928 KB] [1.928 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.432 KB] [2.368 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] [104 B]
should_pass/language/trait_inference [792 B] [760 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 [872 B] [840 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.704 KB] [2.488 KB]
should_pass/language/type_alias_from_dependency [32 B] [32 B]
should_pass/language/type_inference_propagation_of_type_constraints [744 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] [176 B]
should_pass/language/u256/u256_abi [760 B] [744 B]
should_pass/language/u256/u256_operators [3.92 KB] [3.92 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 [704 B] [664 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] [104 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 17, 2025 15:23
@vaivaswatha vaivaswatha requested review from a team as code owners September 17, 2025 15:23
@vaivaswatha
Copy link
Contributor Author

vaivaswatha commented Sep 18, 2025

This PR also address Point #2.a and Point #2.b in #7344.

Sway:

script;

use std::address::Address;

fn main() {
    let _ = wrapper();
}

#[inline(never)]
fn return_option() -> Option<Address> {
    None
}

#[inline(never)]
fn wrapper() -> Address {
    return_option().unwrap()
}

IR before this PR:

fn wrapper_1(__ret_value: __ptr { b256 }) -> __ptr { b256 }, !17 {
        local mut { u64, ( () | { b256 } ) } __aggr_memcpy_0
        local { u64, ( () | { b256 } ) } __matched_value_4
        local { u64, ( () | { b256 } ) } __ret_val
        local { u64, ( () | { b256 } ) } self_
        local { b256 } v

        entry(__ret_value: __ptr { b256 }):
        v0 = get_local __ptr { u64, ( () | { b256 } ) }, __ret_val
        v1 = call return_option_5(v0)
        v2 = get_local __ptr { u64, ( () | { b256 } ) }, __aggr_memcpy_0
        mem_copy_val v2, v1                                             <-------- this gets removed
        v3 = get_local __ptr { u64, ( () | { b256 } ) }, self_, !20
        mem_copy_val v3, v2
        v4 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4, !23
        mem_copy_val v4, v2
        v5 = get_local __ptr { u64, ( () | { b256 } ) }, __aggr_memcpy_0
        v6 = const u64 0
        v7 = get_elem_ptr v5, __ptr u64, v6
        v8 = load v7, !20
        v9 = const u64 1, !24
        v10 = cmp eq v8 v9, !27
        cbr v10, unwrap_2_block0(), unwrap_2_block1(), !28

        unwrap_2_block0():
        v11 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4, !29
        v12 = const u64 1
        v13 = const u64 1
        v14 = get_elem_ptr v11, __ptr { b256 }, v12, v13, !20
        v15 = get_local __ptr { b256 }, v, !31
        mem_copy_val v15, v14                                           <-------- this gets removed
        mem_copy_val __ret_value, v14
        ret __ptr { b256 } __ret_value

        unwrap_2_block1():
        v16 = const u64 0, !32
        revert v16, !37
    }

and IR after this PR:

fn wrapper_1(__ret_value: __ptr { b256 }) -> (), !17 {
        local { u64, ( () | { b256 } ) } __matched_value_4
        local { u64, ( () | { b256 } ) } __ret_val
        local { u64, ( () | { b256 } ) } self_

        entry(__ret_value: __ptr { b256 }):
        v0 = get_local __ptr { u64, ( () | { b256 } ) }, __ret_val
        v1 = call return_option_5(v0)
        v2 = get_local __ptr { u64, ( () | { b256 } ) }, self_, !20
        mem_copy_val v2, v0
        v3 = get_local __ptr { u64, ( () | { b256 } ) }, self_, !23
        v4 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4, !25
        mem_copy_val v4, v3
        v5 = get_local __ptr { u64, ( () | { b256 } ) }, self_
        v6 = const u64 0
        v7 = get_elem_ptr v5, __ptr u64, v6
        v8 = load v7, !20
        v9 = const u64 1, !22
        v10 = cmp eq v8 v9, !28
        cbr v10, unwrap_2_block0(), unwrap_2_block1(), !29

        unwrap_2_block0():
        v11 = get_local __ptr { u64, ( () | { b256 } ) }, __matched_value_4, !30
        v12 = const u64 1
        v13 = const u64 1
        v14 = get_elem_ptr v11, __ptr { b256 }, v12, v13, !20
        mem_copy_val __ret_value, v14
        v15 = const unit ()
        ret () v15

        unwrap_2_block1():
        v16 = const u64 0, !31
        revert v16, !36
    }

lw $r2 $$locbase i8 ; load word
mcpi $r0 $r2 i32 ; copy memory
move $$retv $r0 ; set return value
move $$retv $zero ; set return value
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also remove this 'move'.

Callers are not using them, so I imagine DCE is removing things on the caller side. Which means we can remove this safely here.

Maybe IR needs the concept of fns that do not return anything. Or even a specialized IR/asm generation for ZST?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since that's kind of a separate optimization in itself (in the IR we only return with a value, today), I'll do that as a separate PR

@vaivaswatha vaivaswatha enabled auto-merge (squash) September 19, 2025 09:47
@vaivaswatha vaivaswatha deployed to fuel-sway-bot September 21, 2025 08:21 — with GitHub Actions Active
@vaivaswatha vaivaswatha requested review from xunilrj and a team September 21, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants