Why xor eax, eax?

73 points by krtab


david_chisnall

so it can allocate a fresh, dependency-free zero register renamer slot. And, having done that it removes the operation from the execution queue - that is the xor takes zero execution cycles!1 It’s essentially optimised out by the CPU!

It’s actually better than that because it also marks the old value in the rename register as dead after this point. As soon as all uses within the basic block have retired, the rename register can be reused. In a tight loop, killing a false loop-carried dependency like this can speed things up a surprising amount.