Skip to content

[WebAssembly] Suboptimal lowering of small memsets/memcpys #79692

@SingleAccretion

Description

@SingleAccretion

See this godbolt: link.

define void @suboptimal_memset(ptr) #0 {
    call void @llvm.memset.p0.i32(ptr align 1 %0, i8 0, i32 16, i1 false)
    ret void
}
suboptimal_memset:                      # @suboptimal_memset
        local.get       0
        i64.const       0
        i64.store       0:p2align=0
        local.get       0
        i32.const       8
        i32.add 
        i64.const       0
        i64.store       0:p2align=0
        end_function

Lowering doesn't add the no-wrapping attributes necessary to form WASM address modes. It could, however, as the LLVM model assumes that the destination must be dereferenceable (some prior optimization even adds an attribute to that effect).

Frontend-wise, this forces us to emit a sequence of stores/loads instead of a simple memcpy/memset, so that LLVM reverse folds them back if there are enough. This bloats the IR and complicates code.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions