From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19238 invoked by alias); 21 May 2011 10:09:18 -0000 Received: (qmail 19217 invoked by uid 22791); 21 May 2011 10:09:18 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_OV,TW_RG X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 21 May 2011 10:09:02 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/49095] Horrible code generation for trivial decrement with test X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Target Status Keywords Last reconfirmed Component Ever Confirmed Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sat, 21 May 2011 10:12:00 -0000 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: 2011-05/txt/msg01850.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49095 Richard Guenther changed: What |Removed |Added ---------------------------------------------------------------------------- Target| |x86_64-*-*, i?86-*-* Status|UNCONFIRMED |NEW Keywords| |missed-optimization Last reconfirmed| |2011.05.21 09:52:49 Component|other |rtl-optimization Ever Confirmed|0 |1 --- Comment #1 from Richard Guenther 2011-05-21 09:52:49 UTC --- Confirmed (not using decq is because it is slower for some archs). On the tree level we cannot do better than D.2722_2 = *argv_1(D); D.2723_3 = D.2722_2 + -1; *argv_1(D) = D.2723_3; if (D.2723_3 == 0B) because we lack anything like direct operations on memory (and that's good). On the RTL side combine tries to do Trying 7, 8 -> 9: Failed to match this instruction: (parallel [ (set (mem/f:DI (reg/v/f:DI 63 [ argv ]) [2 *argv_1(D)+0 S8 A64]) (plus:DI (mem/f:DI (reg/v/f:DI 63 [ argv ]) [2 *argv_1(D)+0 S8 A64]) (const_int -1 [0xffffffffffffffff]))) (set (reg/f:DI 60 [ D.2723 ]) (plus:DI (mem/f:DI (reg/v/f:DI 63 [ argv ]) [2 *argv_1(D)+0 S8 A64]) (const_int -1 [0xffffffffffffffff]))) ]) because we have a use of the decrement result in the comparison. It doesn't try to combine this with the comparison though. So this case is really special ;) Without the use of the decremented value we get the desired subq $1, (%rsi). Manually sinking the store to *argv into the if and the else yields movq (%rsi), %rbx subq $1, %rbx je L4 L2: movq %rbx, (%rsi) ... L4: LCFI4: movq $0, (%rsi) movq %rsi, %rdi movq %rsi, 8(%rsp) call _fncall so at least we then can combine the decrement with the test ... As usual combine doesn't like stores.