Skip to content

[dart2wasm] Make use of binaryen's call.without.effects intrinsic #60925

Open
@mkustermann

Description

@mkustermann

Due to our very conservative inlining, sometimes there's calls to functions we know have no effect. If the use-site doesn't use return value, then binaryen could eliminate those calls if we told it that they have no effect.

Example of this is is <type> checkers: We call JSStringImpl._interpolate2 and TFA may infer an argument to be JSStringImpl and another to be just Object?. Now our wasm code may look like this

  (func $JSStringImpl._interpolate2 (;29;) (param $var0 (ref $JSStringImpl)) (param $var1 (ref $#Top)) (result (ref $JSStringImpl))
    local.get $var0
    call $<obj> is String
    drop
    local.get $var0
    struct.get $JSStringImpl $field1
    local.get $var1
    call $<obj> is String
    if (result (ref $JSStringImpl))
      local.get $var1
      ref.cast $JSStringImpl
    else
      local.get $var1
      local.get $var1
      struct.get $#Top $field0
      i32.const 236
      i32.add
      call_indirect (param (ref $#Top)) (result (ref $JSStringImpl))
    end
    struct.get $JSStringImpl $field1
    call $wasm:js-string.concat (import)
    call $JSStringImpl.fromRefUnchecked
  )

Here the call $<obj> is String could be dropped by binaryen if it knew it doesn't have an effect (arguably the dart2wasm compiler could also be smarter and not emit the check in the first place).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart2wasmIssues for the dart2wasm compiler.type-performanceIssue relates to performance or code size

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions