Description
Follow up issue to #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 op
s 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 op
s 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: #11122 (comment)