From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22197 invoked by alias); 16 May 2011 11:39:24 -0000 Received: (qmail 22188 invoked by uid 22791); 16 May 2011 11:39:23 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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; Mon, 16 May 2011 11:39:10 +0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/48986] Missed optimization in atomic decrement on x86/x64 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: X-Bugzilla-Severity: minor X-Bugzilla-Who: jakub 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: Status CC AssignedTo 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: Mon, 16 May 2011 12:07: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/msg01248.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48986 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |NEW CC| |uros at gcc dot gnu.org AssignedTo|jakub at gcc dot gnu.org |unassigned at gcc dot | |gnu.org --- Comment #2 from Jakub Jelinek 2011-05-16 11:26:51 UTC --- On: int foo (int *p) { return __sync_fetch_and_add (p, -1) == 1; } int bar (int *p) { return __sync_add_and_fetch (p, -1) == 0; } I get better generated code for the second routine if I do: --- gcc/config/i386/sync.md.jj 72010-05-21 11:46:29.000000000 +0200 +++ gcc/config/i386/sync.md 2011-05-16 13:06:13.000000000 +0200 @@ -170,7 +170,7 @@ [(match_operand:SWI 1 "memory_operand" "+m")] UNSPECV_XCHG)) (set (match_dup 1) (plus:SWI (match_dup 1) - (match_operand:SWI 2 "register_operand" "0"))) + (match_operand:SWI 2 "nonmemory_operand" "0"))) (clobber (reg:CC FLAGS_REG))] "TARGET_XADD" "lock{%;} xadd{}\t{%0, %1|%1, %0}") and for foo identical code, so maybe that change is always beneficial, allowing combiner and other early RTL passes to see there a constant instead of a REG. Unfortunately, even with this change the combiner doesn't attempt to combine this pattern with the following cmpsi_1 pattern, supposedly because sync_old_addsi pattern isn't single_set. I guess we could handle this during expansion, but it would be a mess, or some other pass (e.g. peephole2 or something similar). peephole2 might kind of too late though, by that time the constant must be loaded already into some register, so we'd need to peephole2 3 insns, where the load of the constant might often not be the first one.