From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6753 invoked by alias); 14 Feb 2013 16:59:33 -0000 Received: (qmail 6642 invoked by uid 48); 14 Feb 2013 16:59:08 -0000 From: "steven at gcc dot gnu.org" 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:59: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: steven 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: CC 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/msg01452.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56309 Steven Bosscher changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |steven at gcc dot gnu.org --- Comment #11 from Steven Bosscher 2013-02-14 16:59:04 UTC --- (In reply to comment #8) > I wonder if instead of emitting this sequence > > shr $0x20,%rdi > and $0xffffffff,%ecx > cmp %r8,%rdx > cmovbe %r11,%rdi > add $0x1,%rax > cmp %r8,%rdx > cmovbe %rdx,%rcx > > it would do this instead > > shr $0x20,%rdi > and $0xffffffff,%ecx > add $0x1,%rax > cmp %r8,%rdx > cmovbe %r11,%rdi > cmovbe %rdx,%rcx GCC fails to do so because the flags are clobbered between the two cmovs, preventing code motion to group the two cmovs: 197: r116:DI={(gtu(flags:CC,0))?r125:DI:r233:DI} 199: {r110:DI=r110:DI+0x1;clobber flags:CC;} 201: flags:CC=cmp(r124:DI,r235:DI) 202: r221:DI={(gtu(flags:CC,0))?r126:DI:r124:DI} If you do this change manually in your code (compile with -S, "fix" the .s file and assemble it), does that speed up your code?