Skip to content

prefer-inline pragmas are not sufficient to do the inlining we want #59685

Open
@osa1

Description

@osa1
import 'dart:typed_data';

@pragma("wasm:prefer-inline")
int sum(List<int> list) {
  int ret = 0;
  for (int i = 0; i < list.length; i += 1) {
    ret += list[i];
  }
  return ret;
}

void main() {
  Int64List intList = Int64List.fromList([1, 2, 3, 4]);
  sum(intList);
  sum([1, 2, 3, 4]);
}

Ideally we want all direct calls to Int64List.[] to be inlined:

@override
@pragma("wasm:prefer-inline")
int operator [](int index) {
indexCheck(index, length);
return _data.read(_offsetInElements + index);
}

But when a call becomes direct after wasm-opt, because we can't control wasm-opt's inliner with a similar pragma, it's not inlined. Relevant parts of the output of the code above:

(func $main (;297;)
  ...
  loop $label1
    local.get $var7
    call $_WasmI64ArrayBase.length initializer
    local.get $var2
    i64.gt_s
    if
      local.get $var4
      local.get $var7
      local.get $var2
      call $I64List.[]
      ref.cast $BoxedInt
      struct.get $BoxedInt $field1
      i64.add
      local.set $var4
      local.get $var2
      i64.const 1
      i64.add
      local.set $var2
      br $label1
    end
  end $label1
  ...
)

Becuase [] is not inlined, each access to the array boxes the integer in the array before returning.

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