From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21497 invoked by alias); 6 Oct 2012 15:56:04 -0000 Received: (qmail 21475 invoked by uid 48); 6 Oct 2012 15:55:49 -0000 From: "daniel.santos at pobox dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/54829] bad optimization: sub followed by cmp w/ zero (x86 & ARM) Date: Sat, 06 Oct 2012 15:56: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: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: daniel.santos at pobox 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: Summary 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: 2012-10/txt/msg00545.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54829 Daniel Santos changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|bad optimization: sub |bad optimization: sub |followed by cmp w/ zero |followed by cmp w/ zero |(ARM) |(x86 & ARM) --- Comment #3 from Daniel Santos 2012-10-06 15:55:47 UTC --- Sure it can: extern print_gt(void); extern print_lt(void); extern print_eq(void); void cmp_and_branch(long a, long b) { if (a > b) { print_gt(); } else if (a < b) { print_lt(); } else { print_eq(); } } Here's x86_64: cmp_and_branch: .LFB0: .cfi_startproc cmpq %rsi, %rdi jg .L5 jl .L6 jmp print_eq .p2align 4,,10 .p2align 3 .L6: jmp print_lt .p2align 4,,10 .p2align 3 .L5: jmp print_gt .cfi_endproc And here's i386: cmp_and_branch: .LFB0: .cfi_startproc movl 8(%esp), %eax cmpl %eax, 4(%esp) jg .L5 jl .L6 jmp print_eq .p2align 2,,3 .L6: jmp print_lt .p2align 2,,3 .L5: jmp print_gt .cfi_endproc