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
bandpatterns as the conditional. This builds on the infrastructure in the previous commit to funnelicmp-equals-zero back up to the top-levelis_nonzero_cmpand then adding rules tois_nonzero_cmpforbandto convert that to atestinstruction which performs thebandand sets the ZF which is what we're interested in.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton has marked PR #11122 as ready for review.
alexcrichton requested wasmtime-compiler-reviewers for a review on PR #11122.
alexcrichton requested abrown for a review on PR #11122.
alexcrichton requested fitzgen for a review on PR #11122.
alexcrichton requested wasmtime-core-reviewers for a review on PR #11122.
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 fora | b,a ^ b,a + b, anda - bif we aren't already doing only a test/compare and are actually unnecessarily explicitly checking for non-zero before the jumps.
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 endwe 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 0x38but we should be able to do something like
or edx, ecx je 0x38 ...
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 endwe 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 0x38but we should be able to do something like
or edx, ecx je 0x38 ...
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
ProducesFlagsinstead ofGpras 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. Basicallybandturned out to be easy becausetesthas the exact semantics ofandwith 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.
fitzgen commented on PR #11122:
I'll make a follow up issue to track this then
alexcrichton merged PR #11122.
Last updated: Dec 06 2025 at 06:05 UTC