This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/37810] Bad store sinking job
- From: "carlo at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Oct 2008 15:32:57 -0000
- Subject: [Bug tree-optimization/37810] Bad store sinking job
- References: <bug-37810-7035@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from carlo at gcc dot gnu dot org 2008-10-12 15:32 -------
Note that the original code was:
A& operator++(void)
{
++n;
if (__builtin_expect(n == m, false))
g();
return *this;
}
but g++ fails to optimize that by decrementing m outside
the loop (so I'm decrementing m myself now and use the
former code). The former code has as advantage, namely,
that the result of the addl $1,%eax can be used for the
conditional jump. However, gcc ALSO doesn't do that: in
the above assembly it follows the add with a redundant
testl %eax,%eax.
Anyway, using the operator++ given in this comment,
the assembly code is:
movl (%rdi), %eax
jmp .L3
.L4:
addl $1, %eax
cmpl 4(%rdi), %eax
movl %eax, (%rdi)
je .L8
.L3:
testl %eax, %eax
jne .L4
which is essentially the same, except now the
testl %eax,%eax is indeed "needed" ...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37810