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

Optimization: Fuse transitive copies #946

Open
Robbepop opened this issue Mar 3, 2024 · 1 comment · Fixed by #969
Open

Optimization: Fuse transitive copies #946

Robbepop opened this issue Mar 3, 2024 · 1 comment · Fixed by #969
Labels
optimization An performance optimization issue.

Comments

@Robbepop
Copy link
Member

Robbepop commented Mar 3, 2024

There are cases where 2 transitive copies are generated such as:

Instruction::copy(2, 0)
Instruction::copy(1, 2)

In this case it is possible to generate a single

Instruction::copy(1, 0)

instead.

An example input where this is currently happening with #945 being merged is:

(module
    (func (param i32) (result i32)
        (local.get 0)
        (block (param i32) (result i32)
            (br 0)
        )
    )
)

Which results in the following Wasmi bytecode:

[
    Instruction::copy(2, 0),
    Instruction::copy(1, 2),
    Instruction::branch(BranchOffset::from(1)),
    Instruction::return_reg(1),
]

This issue wants to optimize the above Wasmi bytecode to the following:

[
    Instruction::copy(1, 0),
    Instruction::branch(BranchOffset::from(1)),
    Instruction::return_reg(1),
]

Note

  1. For reasons of observability this optimization can only be applied if the intermediate result is not the register of a local variable.
  2. The same kind of optimization can and should be applied to copy2 instructions with its two input and result values. An example Wasm input that, together with the previous copy optimization, produces two transitive copy2 instructions:
(func (param i32 i64) (result i32)
    (local.get 0)
    (local.get 1)
    (block (param i32 i64) (result i32 i64)
        (br 0)
    )
    (drop)
)
@Robbepop
Copy link
Member Author

This issue was accidentally/automatically closed when merging #969.

@Robbepop Robbepop reopened this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization An performance optimization issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant