Skip to content

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

@cmichi

Description

@cmichi

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions