Stream: git-wasmtime

Topic: wasmtime / issue #11125 x64: clean up `br_if(op(a, b))` c...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 24 2025 at 17:04):

fitzgen opened issue #11125:

Follow up issue to https://github.com/bytecodealliance/wasmtime/pull/11122

The semantics of br_if are such that we branch to the consequent on a non-zero condition value and the alternative on a zero condition value. Often we are emitting x64 instructions to to the op and then explicitly test whether the result is zero or non-zero and branch accordingly. However, for many ops we can instead just do some kind of test/compare on a and b directly, instead of the op and then a non-zero test.

For example given

    local.get 0
    local.get 1
    i32.or
    if ;; label = @1
      call 0
    else
      call 1
    end

we currently emit the comparison as

00000019    0b d1                             or edx, ecx
0000001b    85 d2                             test edx, edx
0000001d    0f 85 15 00 00 00                 jne 0x38
...

but we should be able to do something like

or edx, ecx
je 0x38
...

instead.

I think that we can add special cases for br_if(op(a, b)) for all ops in {iadd, isub, bor, bxor}. Maybe more. (Note that we already have a br_if(band(a, b)) special case).

Note that doing this might require some additional refactorings in the x64 assembler library and its ISLE constructor generation: https://github.com/bytecodealliance/wasmtime/pull/11122#issuecomment-3001204011

view this post on Zulip Wasmtime GitHub notifications bot (Jun 24 2025 at 20:18):

fitzgen added the cranelift label to Issue #11125.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 24 2025 at 20:18):

fitzgen added the cranelift:goal:optimize-speed label to Issue #11125.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 24 2025 at 20:18):

fitzgen added the cranelift:area:x64 label to Issue #11125.


Last updated: Dec 06 2025 at 06:05 UTC