I am looking at some assembly that was generated by disassembling some C programs and I am confused by a single optimization that I see repeated frequently.
When I have no optimizations on the GCC compiler uses the subl
instruction for subtraction, but when I do have optimizations turned on (-O3
to be precise) the compiler uses a leal
instruction instead of subtraction, example below:
without optimizations:
83 e8 01 subl $0x1, %eax
with optimizations
8d 6f ff leal -0x1(%edi), %ebp
Both of these instructions are 3 bytes long, so I am not seeing an optimization here. Could someone help me out and try to explain the compiler's choice ?
Any help would be appreciated.