From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14636 invoked by alias); 12 Nov 2012 23:22:21 -0000 Received: (qmail 14615 invoked by uid 48); 12 Nov 2012 23:22:07 -0000 From: "olly at survex dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/55299] New: missed optimization: ASR idiom Date: Mon, 12 Nov 2012 23:22:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: olly at survex dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: 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-11/txt/msg01081.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55299 Bug #: 55299 Summary: missed optimization: ASR idiom Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: olly@survex.com This is similar to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54579 but for a different (and perhaps clearer) idiom for arithmetic shift right. I've filed this as a separate PR rather than adding it as a comment, but if it's actually the same issue underneath, please merge or mark as a duplicate. int asr(int a, int b) { return a < 0 ? ~((~a) >> b) : a >> b; } olly@gcc12:~$ /opt/cfarm/gcc-latest/bin/gcc -v Using built-in specs. COLLECT_GCC=/opt/cfarm/gcc-latest/bin/gcc COLLECT_LTO_WRAPPER=/home/iulius/autobuild/bin/gcc-4.7.1/libexec/gcc/x86_64-unknown-linux-gnu/4.7.1/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.7.1-src/configure --prefix=/home/iulius/autobuild/bin/gcc-4.7.1 --with-gmp=/home/iulius/autobuild/bin/gmp-5.0.5 --with-mpfr=/home/iulius/autobuild/bin/mpfr-3.1.0 --with-mpc=/home/iulius/autobuild/bin/mpc-0.9 --disable-nls --enable-threads=posix --disable-multilib --enable-languages=c,c++ Thread model: posix gcc version 4.7.1 (GCC) Compiling with: LD_LIBRARY_PATH=/opt/cfarm/mpc-latest/lib:/opt/cfarm/mpfr-latest/lib:/opt/cfarm/gmp-latest/lib /opt/cfarm/gcc-latest/bin/gcc -O2 -S asr.c -o asr.S Gives this for the function asr: asr: .LFB0: movl %edi, %eax movl %esi, %ecx sarl %cl, %eax testl %edi, %edi js .L5 rep ret .p2align 4,,10 .p2align 3 .L5: movl %edi, %eax notl %eax sarl %cl, %eax notl %eax ret Ideally the conditional would be optimised down to just the sarl instruction. I've checked the older compiler versions on gcc12 (back to 4.1.1) and they all leave the branch in. So if this is a regression, it isn't at all recent.