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].
[^1] : https://qa.1r1g.com/sf/ask/4066329221/
标签:case,xor,practice,mov,eax,Optimization,more From: https://www.cnblogs.com/UQ-44636346/p/17047850.html