Skip to content

[WebAseembly] Zero-length checks for constant-sized bulk memory ops #163245

@SingleAccretion

Description

@SingleAccretion

I noticed this a bit surprising code quality regression while trying out the new LLVM that uses bulk memory by default.

Godbolt link.

C source:

void test_fill(int* d, int* s)  {
    __builtin_memset(d, 0, 128);
}

void test_copy(int* d, int* s)  {
    __builtin_memcpy(d, s, 128);
}

Output:

test_fill(int*, int*):
        block           
        i32.const       128
        i32.eqz
        br_if           0
        local.get       0
        i32.const       0
        i32.const       128
        memory.fill     0
        end_block
        end_function

test_copy(int*, int*):
        block           
        i32.const       128
        i32.eqz
        br_if           0
        local.get       0
        local.get       1
        i32.const       128
        memory.copy     0, 0
        end_block
        end_function

Notice the useless checks.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions