Skip to content

[WASM] Suboptimal memcmp expansion for odd lengths #61400

@MaxGraey

Description

@MaxGraey

Example (Godbolt)

Calls to memcmp(a, b, n) == 0, where n is odd is suboptimal for wasm32 target where such call didn't lower to expansion and calls memcmp routine even for small lengths (n < 16)

Here codegen for memcmp(a, "abc", 3) == 0:

x64

movzx   eax, word ptr [rdi]
xor     eax, 25185
movzx   ecx, byte ptr [rdi + 2]
xor     ecx, 99
or      cx, ax
sete    al
ret

wasm32 (actual)

local.get  0
i32.const  .L.str.2
i32.const  3
call       memcmp
i32.eqz

wasm32 (expected)

local.get    0
i32.load16_u 0     ;;align=1 ???
i32.const    25185
i32.xor 
local.get    0
i32.load8_u  2
i32.const    99
i32.xor 
i32.or  
i32.eqz

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions