GCC changes less than less than or equal to

I have the following simple program that I use to update my memory about GDB (which I have not touched for many years).

#include <stdio.h>

int main()
{
  int i;

  for (i = 0; i < 10; i++)
  {
    printf("Hello World\n");
  }

  return 0;
}

I will compile this with gcc -g for-test.c -o for-test. Based on the man page, I do not expect any optimizations to be used since I did not specify any.

When I load this into GDB and run disassemble main, the comparison i < 10generates the following:

cmp    DWORD PTR [rbp-0x4],0x9
jle    0x4004fe <main+10>

This seems to have effectively changed the comparison i < 10to i <= 9. Given that these are whole comparisons, there shouldn't be a difference, but I was wondering if there is any reason GCC displays this assembly instead of comparing with 10 and jumps if less (JL)?

Edit: this is on a computer with a 64-bit processor running Ubuntu with GCC 4.6.3 and GDB 7.4-2012.04.

+5
3

. , gcc jle .

+5

, . As-If. , . , .

+2

This is not an effective optimization, but just another way to write the same thing. Compiling with the -O flag generates much more complex optimizations.

0
source

All Articles