Stream: git-wasmtime

Topic: wasmtime / PR #11122 x64: Optimize branch-with-`band`


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

alexcrichton opened PR #11122 from alexcrichton:x64-branch-with-band to bytecodealliance:main:

This commit adds new lowering patterns for the x64 backend to optimize conditional branches with band patterns as the conditional. This builds on the infrastructure in the previous commit to funnel icmp-equals-zero back up to the top-level is_nonzero_cmp and then adding rules to is_nonzero_cmp for band to convert that to a test instruction which performs the band and sets the ZF which is what we're interested in.

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->

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

alexcrichton has marked PR #11122 as ready for review.

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

alexcrichton requested wasmtime-compiler-reviewers for a review on PR #11122.

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

alexcrichton requested abrown for a review on PR #11122.

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

alexcrichton requested fitzgen for a review on PR #11122.

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

alexcrichton requested wasmtime-core-reviewers for a review on PR #11122.

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

fitzgen submitted PR review:

Does it make sense to enumerate all br_if(op(a, b)) in a similar way? I think we can probably have similar-ish patterns for a | b, a ^ b, a + b, and a - b if we aren't already doing only a test/compare and are actually unnecessarily explicitly checking for non-zero before the jumps.

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

fitzgen commented on PR #11122:

Yeah, 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
...

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

fitzgen edited a comment on PR #11122:

Yeah, 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
...

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

alexcrichton commented on PR #11122:

I think that makes sense to do yeah and was something I was curious about, but doing this robustly I think will require deeper refactorings of ISLE integration with the new assembler to, for example, auto-generate constructors which return ProducesFlags instead of Gpr as they do today. Instruction-selection for mem/imm/etc then also gets a bit tricky if we don't want to have too too much duplication. Basically band turned out to be easy because test has the exact semantics of and with the main benefit of a register isn't written, only flags.

So given the amount of refactoring/infrastructure I think the other patterns are going to need I'll defer that for a future change.

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

fitzgen commented on PR #11122:

I'll make a follow up issue to track this then

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

alexcrichton merged PR #11122.


Last updated: Dec 06 2025 at 06:05 UTC