I noticed in my JIT compiled program that there are a lot of cases where a register is tested against zero (for example: equal to, not equal to). The code generation would emit something like (below are opcodes):
cmp $0x0,%r14
49 83 fe 00
je 0x000000000000307a
0f 84 89 05 00 00
For example, if I know that a certain register is always unused in my program, would it make sense to use that as a zero-register (initialise once) and do the compare against it in order to shrink the overall program size?
cmp %rdx,%rsi
48 39 d6
Or, from a modern x86 CPU internals perspective would that rather turn out to be slower to use the register as it does some internal magic on the 0 immediate used in the comparison? Are there other, more efficient approaches I've been missing in terms of encoding size and cycles?