This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ix86 optimizer vagaries?


On Nov 8, 2003, at 09:57, Roberto Bagnara wrote:
I am confused: why GCC 3.3.2 generates code for

unsigned
f1(unsigned n) {
  return 2*(n + 1);
}

that is significantly better than the one generated for

unsigned
f2(unsigned n) {
  return 2*(++n);
}

which, however, in the attached program runs significantly
faster than the code obtained by using

unsigned
f3(unsigned n) {
  unsigned m = n;
  ++m;
  m *= 2;
  return m;
}


I think your times are messed up because f3 and f2 produce the same asm
(also the same asm for 3.3.1):
        .file   "testopt.c"
        .text
        .p2align 4,,15
.globl f1
        .type   f1, @function
f1:
        movl    4(%esp), %eax
        leal    2(%eax,%eax), %eax
        ret
        .size   f1, .-f1
        .p2align 4,,15
.globl f2
        .type   f2, @function
f2:
        movl    4(%esp), %eax
        incl    %eax
        addl    %eax, %eax
        ret
        .size   f2, .-f2
        .p2align 4,,15
.globl f3
        .type   f3, @function
f3:
        movl    4(%esp), %eax
        incl    %eax
        addl    %eax, %eax
        ret
        .size   f3, .-f3
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4 20031108 (experimental)"



Thanks,
Andrew Pinski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]