Skip to content

wasm-opt failes to optimize in some cases #213

@mokurin000

Description

@mokurin000

This issue is for explaining the reason we need each flag I added in #191

Also see: trunk-rs/trunk#866

optional WASM feature of wasm-opt

There are wasm features that wasm-opt does not support by default, including:

  • --enable-bulk-memory is for memcpy like instructtions: memory.copy, memory.fill, ...1
  • --enable-nontrapping-float-to-int provides _sat variants of ixx.trunc_fxx_s 2
  • --enable-threads enables atomic operations. WASM is currently single-threaded though

LLVM used the _sat for its fp_to_sint_sat

A empty repo (whether added poll_promise) will compile with trunk under release mode fine, but once one of them are involved, we must provide such options.

I'm trying to write a minimum reproduce code, but it's hard to know how to make the assembly result contain specific instruction without naked asm.

This also depends on LLVM version, because rustc compiles to LLVM IR.

For my rustc 1.93 and doukutsu-save-editor, I found --enable-threads can be removed, but --enable-bulk-memory and --enable-nontrapping-float-to-int were used

Looking into LLVM source code, the wasm memcpy was defined as CPY_A#B, COPY_A#B, etc.

And to determine whether it's being used, see llvm frontend code, and look.up for COPY_I32, COPY_I64.

Footnotes

  1. https://github.com/WebAssembly/spec/blob/main/proposals/bulk-memory-operations/Overview.md

  2. https://github.com/WebAssembly/spec/blob/main/proposals/nontrapping-float-to-int-conversion/Overview.md

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