fitzgen opened issue #11125:
Follow up issue to https://github.com/bytecodealliance/wasmtime/pull/11122
The semantics of
br_ifare 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 theopand then explicitly test whether the result is zero or non-zero and branch accordingly. However, for manyops we can instead just do some kind of test/compare onaandbdirectly, instead of theopand then a non-zero test.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 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 allops in{iadd, isub, bor, bxor}. Maybe more. (Note that we already have abr_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
fitzgen added the cranelift label to Issue #11125.
fitzgen added the cranelift:goal:optimize-speed label to Issue #11125.
fitzgen added the cranelift:area:x64 label to Issue #11125.
Last updated: Dec 06 2025 at 06:05 UTC