Optimization practice xor OR mov
There are two snippets of codes after optimized by the compiler with levels 1 and 3:
(This code is responsible for "return 0" in the body of the main function!)
case 1:
movl $0, %eax
case 2:
xorl %eax, %eax
Case 2 is optimized by GCC with level 3, which is definitely more efficient than case 1.
WHY?
This is because the more work of decoding the immediate number 0 in case 1 makes it inefficient [1].

浙公网安备 33010602011771号