From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32566 invoked by alias); 14 Feb 2013 16:44:04 -0000 Received: (qmail 31943 invoked by uid 48); 14 Feb 2013 16:43:24 -0000 From: "arturomdn at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/56309] -O3 optimizer generates conditional moves instead of compare and branch resulting in almost 2x slower code Date: Thu, 14 Feb 2013 16:44:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: arturomdn at gmail dot com 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: 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 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: 2013-02/txt/msg01449.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56309 --- Comment #10 from arturomdn at gmail dot com 2013-02-14 16:43:23 UTC --- Might be worth mentioning here what I said in the stackoverflow answer, that in this particular case the entire conditional branch can be avoided because it is redundant. This code if (tmp >= imax) { carry = tmp >> numbits; // <---- A tmp &= imax - 1; // <---- B } else { carry = 0; // <---- C } can be reduced to carry = tmp >> numbits; tmp &= imax - 1; Proof: 1) numbits is 32 2) imax is 1ULL << 32 so lower 32 bits are zero 3) imax - 1 is 0xFFFFFFFF (see 2) 4) if tmp >= imax then tmp has bits set in upper 32 bits 5) otherwise if tmp < imax then tmp does not have bits set in upper 32 bits 6) statement "A" is equivalent to "C" when tmp < imax (because of 4) 7) statement "B" is a NOP when tmp < imax (because of 3 and 5)