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

Optimizations are executed, even if chosen level is 0 #56

Open
cmichi opened this issue Mar 23, 2021 · 0 comments
Open

Optimizations are executed, even if chosen level is 0 #56

cmichi opened this issue Mar 23, 2021 · 0 comments

Comments

@cmichi
Copy link

cmichi commented Mar 23, 2021

I discovered this when executing tests for a project which uses binaryen-rs as a dependency. The project sets the optimization level to 0 during some tests.

From wasm-opt --help:

   -O0                                          execute no optimization passes 

The wasm-opt behavior:

$ wasm-opt -O0 --shrink-level=0 -o output.wasm flipper.wasm
warning: no passes specified, not doing any work

But binaryen-rs still optimizes if the optimization level and the shrink level is both set to 0:

#[test]
fn must_not_optimize_for_level_zero() {
    let input: Vec<u8> = vec![
        0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60, 0x00, 0x00,
        0x03, 0x02, 0x01, 0x00, 0x07, 0x08, 0x01, 0x04, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00,
        0x08, 0x01, 0x00, 0x0a, 0x04, 0x01, 0x02, 0x00, 0x0b,
    ];

    let codegen_config = binaryen::CodegenConfig {
        optimization_level: 0,
        shrink_level: 0,
        debug_info: true,
    };
    let mut module = binaryen::Module::read(&input).unwrap();
    module.optimize(&codegen_config);

    // no optimization should have happened
    assert_eq!(module.write(), input);
}

This test fails for master.

I only quickly searched in the code and my hunch is that this could be a reason:

passRunner.addDefaultOptimizationPasses();

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

No branches or pull requests

1 participant