Skip to content

Conversation

vaivaswatha
Copy link
Contributor

@vaivaswatha vaivaswatha commented Oct 6, 2025

Description

For the Sway code in #7344, the IR after #7381 and after this PR is shown here:

After #7381, before 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
    }

    fn return_option_5(__ret_value: __ptr { u64, ( () | { b256 } ) }) -> (), !39 {
        local { u64, ( () | { b256 } ) } __anon_0

        entry(__ret_value: __ptr { u64, ( () | { b256 } ) }):
        v0 = get_local __ptr { u64, ( () | { b256 } ) }, __anon_0, !40
        v1 = const u64 0
        v2 = get_elem_ptr v0, __ptr u64, v1, !40
        v3 = const u64 0, !40
        store v3 to v2, !40
        mem_copy_val __ret_value, v0
        v4 = const unit ()
        ret () v4
    }
After this PR
    fn wrapper_1(__ret_value: __ptr { b256 }) -> (), !17 {
        local { u64, ( () | { b256 } ) } __ret_val

        entry(__ret_value: __ptr { b256 }):
        v0 = get_local __ptr { u64, ( () | { b256 } ) }, __ret_val
        v1 = call return_option_5(v0)
        mem_copy_val __ret_value, v0
        v2 = const u64 0
        v3 = get_elem_ptr __ret_value, __ptr u64, v2
        v4 = load v3, !20
        v5 = const u64 1, !22
        v6 = cmp eq v4 v5, !25
        cbr v6, unwrap_2_block0(), unwrap_2_block1(), !26

        unwrap_2_block0():
        v7 = const unit ()
        ret () v7

        unwrap_2_block1():
        v8 = const u64 0, !27
        revert v8, !32
    }

    fn return_option_5(__ret_value: __ptr { u64, ( () | { b256 } ) }) -> (), !35 {
        entry(__ret_value: __ptr { u64, ( () | { b256 } ) }):
        v0 = const u64 0
        v1 = get_elem_ptr __ret_value, __ptr u64, v0, !36
        v2 = const u64 0, !36
        store v2 to v1, !36
        v3 = const unit ()
        ret () v3
    }

wrapper_1, which had 3 memcpys now only has 1, and return_option_5 which had one, now has none.

Closes #7344.

Copy link

codspeed-hq bot commented Oct 6, 2025

CodSpeed Performance Report

Merging #7443 will not alter performance

Comparing vaivaswatha/memcpy_prop_new (96127a8) with master (74bab18)

Summary

✅ 25 untouched

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.

Eliminate mem_copy_vals when returning aggregates
1 participant