From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18489 invoked by alias); 12 Oct 2008 15:34:17 -0000 Received: (qmail 18033 invoked by uid 48); 12 Oct 2008 15:32:57 -0000 Date: Sun, 12 Oct 2008 15:34:00 -0000 Message-ID: <20081012153257.18032.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug tree-optimization/37810] Bad store sinking job In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "carlo at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-10/txt/msg00793.txt.bz2 ------- 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