The circuitry to determine that the contents of eax
after test eax, eax
are the same as before the instruction is simpler than the circuitry required to arrive to that conclusion for or eax, eax
. For this reason, test
is better.
Some compilers may have generated or
at a time when it did not make any difference (before out-of-order execution), but it will make a difference with some out-of-order processors nowadays (whereas yet other OOO processors will be so sophisticated that they will recognize or eax, eax
as truly equivalent to test eax, eax
).
I couldn't find a reference justifying that some modern processors are actually able to infer that or reg, reg
does not modify reg
, but here is an answer claiming it is the case for xchg reg, reg
.