This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: ix86 optimizer vagaries?
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Roberto Bagnara <bagnara at cs dot unipr dot it>
- Cc: gcc at gcc dot gnu dot org, Andrew Pinski <pinskia at physics dot uc dot edu>
- Date: Sat, 8 Nov 2003 10:10:10 -0800
- Subject: Re: ix86 optimizer vagaries?
- References: <3FAD2E96.2050100@cs.unipr.it>
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