Closed
Description
There are some well-known bit manipulation patterns that the JIT doesn't currently optimize. For instance:
public static bool AreZero(int x, int y) {
return x == 0 && y == 0;
}
Produces this codegen:
AreZero(Int32, Int32)
L0000: test ecx, ecx
L0002: jnz L000d
L0004: test edx, edx
L0006: setz al
L0009: movzx eax, al
L000c: ret
L000d: xor eax, eax
L000f: ret
But it could produce this more optimal codegen, folding the two comparisons together into a single or
and zero check:
AreZero(Int32, Int32)
L0000: or edx, ecx
L0002: setz al
L0005: movzx eax, al
L0008: ret
category:cq
theme:basic-cq
skill-level:beginner
cost:small