From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7995 invoked by alias); 10 Jul 2012 10:24:21 -0000 Received: (qmail 7979 invoked by uid 22791); 10 Jul 2012 10:24:19 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED,TW_BJ,TW_CX,TW_GX 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; Tue, 10 Jul 2012 10:24:06 +0000 From: "daniel.santos at pobox dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets Date: Tue, 10 Jul 2012 10:24:00 -0000 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: enhancement X-Bugzilla-Who: daniel.santos at pobox dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rask 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: 2012-07/txt/msg00823.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3507 Daniel Santos changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |daniel.santos at pobox dot | |com --- Comment #13 from Daniel Santos 2012-07-10 10:23:08 UTC --- Well here's another test case for the same problem: extern print_gt(void); extern print_lt(void); extern print_eq(void); void cmp_and_branch(long a, long b) { long diff = a - b; if (diff > 0) { print_gt(); } else if (diff < 0) { print_lt(); } else { print_eq(); } } In this case, the result of the subtraction is directly used in the branch code. However, gcc -O2 -S still generates this output: .file "gcc_cmp_and_branch_test2.c" .text .p2align 4,,15 .globl cmp_and_branch .type cmp_and_branch, @function cmp_and_branch: .LFB0: .cfi_startproc subq %rsi, %rdi cmpq $0, %rdi jg .L5 jne .L6 jmp print_eq .p2align 4,,10 .p2align 3 .L5: jmp print_gt .p2align 4,,10 .p2align 3 .L6: jmp print_lt .cfi_endproc .LFE0: .size cmp_and_branch, .-cmp_and_branch .ident "GCC: (Gentoo 4.7.1) 4.7.1" .section .note.GNU-stack,"",@progbits I'm using Gentoo x86_64: Using built-in specs. COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.1/gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.7.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /tmp/portage/sys-devel/gcc-4.7.1/work/gcc-4.7.1/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.1 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --with-ppl --with-cloog --disable-ppl-version-check --with-cloog-include=/usr/include/cloog-ppl --enable-lto --enable-nls --without-included-gettext --with-system-zlib --enable-obsolete --disable-werror --enable-secureplt --enable-multilib --with-multilib-list=m32,m64 --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/python --enable-checking=release --enable-java-awt=gtk --enable-objc-gc --enable-languages=c,c++,java,objc,obj-c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.7.1' Thread model: posix gcc version 4.7.1 (Gentoo 4.7.1) I do hope this can be addressed sometime soon. Thanks.